예제 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            var account = Account.Get(context);
            var pstPath = PstFilePath.Get(context);

            OutlookAPI.ArchiveMails(account, pstPath);
        }
        public Task <List <MailMessage> > GetMessages(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            string account    = Account.Get(context);
            string filter     = Filter.Get(context);
            string folderpath = MailFolder.Get(context);
            int    top        = Top.Get(context);

            return(Task.Factory.StartNew(() => OutlookAPI.GetMessages(account, folderpath, top, filter, OnlyUnreadMessages, MarkAsRead, true, cancellationToken)));
        }
        private Task <object> MoveMessageAction(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            MailMessage message = MailMessage.Get(context);

            return(Task.Factory.StartNew(((Func <object>) delegate
            {
                OutlookAPI.DeleteMessage(message);
                return null;
            })));
        }
예제 #4
0
        private Task <object> MoveMessageAction(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            MailMessage message    = MailMessage.Get(context);
            string      folderpath = MailFolder.Get(context);
            string      account    = Account.Get(context);

            return(Task.Factory.StartNew(((Func <object>) delegate
            {
                OutlookAPI.MoveMessage(message, folderpath, account);
                return null;
            })));
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            int         num         = TimeoutMS.Get(context);
            string      body        = Body.Get(context);
            MailMessage mailMessage = MailMessage.Get(context);

            if (mailMessage == null)
            {
                throw new ArgumentNullException("MailMessage对象不能为空!");
            }
            MailMessage   message     = mailMessage;
            List <string> attachments = new List <string>();

            foreach (InArgument <string> file in Files)
            {
                AddAttachments(attachments, file.Get(context));
            }
            foreach (string item in AttachmentsCollection.Get(context).EmptyIfNull())
            {
                AddAttachments(attachments, item);
            }
            num = ((num <= 0) ? DefaultTimeoutMS : num);
            using (CancellationTokenSource timeoutCts = new CancellationTokenSource(num))
            {
                using (CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken))
                {
                    try
                    {
                        await OutlookAPI.ReplyToAsync(message, body, attachments, ReplyAll, cts.Token);
                    }
                    catch (OperationCanceledException)
                    {
                        if (timeoutCts.IsCancellationRequested)
                        {
                            throw new TimeoutException();
                        }
                        throw;
                    }
                }
            }
            return(delegate
            {
            });
        }
        public Task SendMailTask(AsyncCodeActivityContext context, Receiver reciever, MailMessage mailMessage, CancellationToken cancellationToken, bool isNewMessage, string body)
        {
            List <string> attachments = Attachments ?? new List <string>();

            foreach (InArgument <string> file in Files)
            {
                AddAttachments(attachments, file.Get(context));
            }
            foreach (string item in AttachmentsCollection.Get(context).EmptyIfNull())
            {
                AddAttachments(attachments, item);
            }
            string to  = To.Get(context);
            string cc  = Cc.Get(context);
            string bcc = Bcc.Get(context);
            string sentOnBehalfOfName = SentOnBehalfOfName.Get(context);
            string account            = Account.Get(context);

            return(Task.Factory.StartNew(delegate
            {
                OutlookAPI.SendMail(mailMessage, account, sentOnBehalfOfName, to, cc, bcc, attachments, IsDraft, IsBodyHtml);
            }));
        }
예제 #7
0
        private static List <MailMessage> GetMessages(MAPIFolder inboxFolder, int count, string filter, bool onlyUnread, bool markAsRead, bool getAttachments, CancellationToken cancellationToken)
        {
            Items items             = null;
            List <MailMessage> list = new List <MailMessage>();

            try
            {
                if (inboxFolder == null)
                {
                    throw new ArgumentException("找不到指定的邮件目录!");
                }
                bool    flag  = !string.IsNullOrEmpty(filter);
                bool    flag2 = true;
                dynamic obj   = null;
                items = inboxFolder.Items;
                items.Sort("[ReceivedTime]", true);
                if (flag && onlyUnread)
                {
                    obj = ((!filter.StartsWith("@SQL=", StringComparison.OrdinalIgnoreCase)) ? items.Find($"({filter}) and [UnRead] = True") : items.Find($"@SQL=(({filter.Substring(5)}) AND (\"urn:schemas:httpmail:read\" = 0))"));
                }
                else if (onlyUnread)
                {
                    obj = items.Find($"[UnRead] = {onlyUnread}");
                }
                else if (flag)
                {
                    obj = items.Find($"{filter}");
                }
                else
                {
                    obj   = items.GetFirst();
                    flag2 = false;
                }
                int num = 0;
                while (true)
                {
                    if (!((obj != null) ? true : false))
                    {
                        return(list);
                    }
                    if (num == count)
                    {
                        return(list);
                    }
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                    if (obj is MailItem)
                    {
                        if (markAsRead)
                        {
                            obj.UnRead = false;
                        }
                        list.Add(OutlookAPI.CreateMailMessageFromOutlookMailItem(obj, getAttachments, null));
                        num++;
                    }
                    obj = (flag2 ? items.FindNext() : items.GetNext());
                }
                return(list);
            }
            finally
            {
                if (inboxFolder != null)
                {
                    Marshal.ReleaseComObject(inboxFolder);
                }
            }
        }