Exemple #1
0
        public IEnumerable <int> MoveMessages(List <int> ids, int folder, uint?userFolderId = null)
        {
            if (!ids.Any())
            {
                throw new ArgumentException(@"Empty ids collection", "ids");
            }

            var toFolder = (FolderType)folder;

            if (!MailFolder.IsIdOk(toFolder))
            {
                throw new ArgumentException(@"Invalid folder id", "folder");
            }

            MailEngineFactory.MessageEngine.SetFolder(ids, toFolder, userFolderId);

            SendUserActivity(ids, MailUserAction.MoveTo, folder);

            if (toFolder == FolderType.Spam || toFolder == FolderType.Sent || toFolder == FolderType.Inbox)
            {
                MailEngineFactory.OperationEngine.ApplyFilters(ids);
            }

            return(ids);
        }
Exemple #2
0
        public IEnumerable <int> MoveConversations(List <int> ids, int folder, uint?userFolderId = null)
        {
            if (!ids.Any())
            {
                throw new ArgumentException(@"Empty ids collection", "ids");
            }

            var toFolder = (FolderType)folder;

            if (!MailFolder.IsIdOk(toFolder))
            {
                throw new ArgumentException(@"Invalid folder id", "folder");
            }

            MailEngineFactory.ChainEngine.SetConversationsFolder(ids, toFolder, userFolderId);

            if (toFolder != FolderType.Spam)
            {
                return(ids);
            }

            //TODO: Try to move message (IMAP only) to spam folder on original server (need new separated operation)

            var scheme = HttpContext.Current == null ? Uri.UriSchemeHttp : HttpContext.Current.Request.GetUrlRewriter().Scheme;

            MailEngineFactory.SpamEngine.SendConversationsToSpamTrainer(TenantId, Username, ids, true, scheme);

            return(ids);
        }
Exemple #3
0
        public int LoadSampleMessage(
            int?folderId,
            uint?userFolderId,
            int?mailboxId,
            bool unread,
            Stream emlStream,
            bool add2Index = false)
        {
            var folder = folderId.HasValue ? (FolderType)folderId.Value : FolderType.Inbox;

            if (!MailFolder.IsIdOk(folder))
            {
                throw new ArgumentException(@"Invalid folder id", "folderId");
            }

            if (!mailboxId.HasValue)
            {
                throw new ArgumentException(@"Invalid mailbox id", "mailboxId");
            }

            var accounts = _engineFactory.AccountEngine.GetAccountInfoList().ToAccountData().ToList();

            var account = mailboxId.HasValue
                ? accounts.FirstOrDefault(a => a.MailboxId == mailboxId)
                : accounts.FirstOrDefault(a => a.IsDefault) ?? accounts.FirstOrDefault();

            if (account == null)
            {
                throw new ArgumentException("Mailbox not found");
            }

            var mbox = _engineFactory.MailboxEngine.GetMailboxData(
                new СoncreteUserMailboxExp(account.MailboxId, TenantId, Username));

            if (mbox == null)
            {
                throw new ArgumentException("no such mailbox");
            }

            var mimeMessage = MailClient.ParseMimeMessage(emlStream);

            var message = MessageEngine.Save(mbox, mimeMessage, SAMPLE_UIDL, new MailFolder(folder, ""), userFolderId,
                                             unread, Log);

            if (message == null)
            {
                return(-1);
            }

            if (!add2Index)
            {
                return(message.Id);
            }

            _engineFactory.IndexEngine.Add(message.ToMailWrapper(mbox.TenantId, new Guid(mbox.UserId)));

            return(message.Id);
        }
Exemple #4
0
        public int CreateSampleMessage(
            int?folderId,
            int?mailboxId,
            List <string> to,
            List <string> cc,
            List <string> bcc,
            bool importance,
            bool unread,
            string subject,
            string body,
            string calendarUid   = null,
            DateTime?date        = null,
            List <int> tagIds    = null,
            string fromAddress   = null,
            bool add2Index       = false,
            string mimeMessageId = null,
            uint?userFolderId    = null)
        {
            var folder = folderId.HasValue ? (FolderType)folderId.Value : FolderType.Inbox;

            if (!MailFolder.IsIdOk(folder))
            {
                throw new ArgumentException(@"Invalid folder id", "folderId");
            }

            if (!mailboxId.HasValue)
            {
                throw new ArgumentException(@"Invalid mailbox id", "mailboxId");
            }

            var accounts = _engineFactory.AccountEngine.GetAccountInfoList().ToAccountData().ToList();

            var account = mailboxId.HasValue
                ? accounts.FirstOrDefault(a => a.MailboxId == mailboxId)
                : accounts.FirstOrDefault(a => a.IsDefault) ?? accounts.FirstOrDefault();

            if (account == null)
            {
                throw new ArgumentException("Mailbox not found");
            }

            var mbox = _engineFactory.MailboxEngine.GetMailboxData(
                new СoncreteUserMailboxExp(account.MailboxId, TenantId, Username));

            if (mbox == null)
            {
                throw new ArgumentException("no such mailbox");
            }

            var internalId = string.IsNullOrEmpty(mimeMessageId) ? MailUtil.CreateMessageId() : mimeMessageId;

            var restoreFolder = folder == FolderType.Spam || folder == FolderType.Trash
                ? FolderType.Inbox
                : folder;

            string sampleBody;
            string sampleIntro;

            if (!to.Any())
            {
                to = new List <string> {
                    mbox.EMail.Address
                };
            }

            if (!string.IsNullOrEmpty(body))
            {
                sampleBody  = body;
                sampleIntro = MailUtil.GetIntroduction(body);
            }
            else
            {
                sampleBody  = LOREM_IPSUM_BODY;
                sampleIntro = LOREM_IPSUM_INTRO;
            }

            var sampleMessage = new MailMessage
            {
                Date            = date ?? DateTime.UtcNow,
                MimeMessageId   = internalId,
                MimeReplyToId   = null,
                ChainId         = internalId,
                ReplyTo         = "",
                To              = string.Join(", ", to.ToArray()),
                Cc              = cc.Any() ? string.Join(", ", cc.ToArray()) : "",
                Bcc             = bcc.Any() ? string.Join(", ", bcc.ToArray()) : "",
                Subject         = string.IsNullOrEmpty(subject) ? LOREM_IPSUM_SUBJECT : subject,
                Important       = importance,
                TextBodyOnly    = false,
                Attachments     = new List <MailAttachmentData>(),
                Size            = sampleBody.Length,
                MailboxId       = mbox.MailBoxId,
                HtmlBody        = sampleBody,
                Introduction    = sampleIntro,
                Folder          = folder,
                RestoreFolderId = restoreFolder,
                IsNew           = unread,
                StreamId        = MailUtil.CreateStreamId(),
                CalendarUid     = calendarUid
            };

            if (!string.IsNullOrEmpty(fromAddress))
            {
                var from = Parser.ParseAddress(fromAddress);

                sampleMessage.From      = from.ToString();
                sampleMessage.FromEmail = from.Email;
            }
            else
            {
                sampleMessage.From      = MailUtil.CreateFullEmail(mbox.Name, mbox.EMail.Address);
                sampleMessage.FromEmail = mbox.EMail.Address;
            }

            if (tagIds != null && tagIds.Any())
            {
                sampleMessage.TagIds = tagIds;
            }

            MessageEngine.StoreMailBody(mbox, sampleMessage, Log);

            var id = _engineFactory.MessageEngine.MailSave(mbox, sampleMessage, 0, folder, restoreFolder, userFolderId,
                                                           SAMPLE_UIDL, "", false);

            if (!add2Index)
            {
                return(id);
            }

            var message = _engineFactory.MessageEngine.GetMessage(id, new MailMessageData.Options());

            message.IsNew = unread;

            var wrapper = message.ToMailWrapper(mbox.TenantId, new Guid(mbox.UserId));

            _engineFactory.IndexEngine.Add(wrapper);

            return(id);
        }