Beispiel #1
0
        protected override void Execute(NativeActivityContext context)
        {
            var folder     = Folder.Get(context);
            var maxresults = MaxResults.Get(context);
            var filter     = Filter.Get(context);

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }
            var outlookApplication = CreateOutlookInstance();

            if (outlookApplication.ActiveExplorer() == null)
            {
                Log.Warning("Outlook not running!");
                return;
            }
            MAPIFolder inBox = (MAPIFolder)outlookApplication.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            // MAPIFolder folderbase = inBox.Store.GetRootFolder();
            var        folderbase = outlookApplication.GetNamespace("MAPI");
            MAPIFolder mfolder    = GetFolder(folderbase, folder);

            Items Items      = mfolder.Items;
            var   unreadonly = UnreadOnly.Get(context);

            if (unreadonly)
            {
                if (string.IsNullOrEmpty(filter))
                {
                    filter = "";
                }
                //if (!filter.ToLower().Contains("[unread]") && filter.ToLower().Contains("httpmail:read"))
                //{
                if (string.IsNullOrEmpty(filter))
                {
                    filter = "[Unread]=true";
                }
                else
                {
                    filter += "and [Unread]=true";
                }
                // }
                // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:hasattachment" + (char)34 + "=1 AND " +
                // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:read" + (char)34 + "=0";
            }
            else
            {
            }
            if (!string.IsNullOrEmpty(filter))
            {
                Items = Items.Restrict(filter);
            }

            var result = new List <email>();

            foreach (var folderItem in Items)
            {
                MailItem mailItem = folderItem as MailItem;
                if (mailItem != null)
                {
                    var _e = new email(mailItem);
                    result.Add(_e);
                    if (result.Count == maxresults)
                    {
                        break;
                    }
                }
            }
            Emails.Set(context, result);
            IEnumerator <email> _enum = result.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Beispiel #2
0
        protected override void Execute(NativeActivityContext context)
        {
            var folder = Folder.Get(context);

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }
            var outlookApplication = CreateOutlookInstance();

            if (outlookApplication.ActiveExplorer() == null)
            {
                Log.Warning("Outlook not running!");
                return;
            }
            MAPIFolder inBox      = (MAPIFolder)outlookApplication.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            MAPIFolder folderbase = inBox.Store.GetRootFolder();
            MAPIFolder mfolder    = GetFolder(folderbase, folder);

            Items Items      = mfolder.Items;
            var   unreadonly = UnreadOnly.Get(context);

            if (unreadonly)
            {
                var Filter = "[Unread]=true";
                // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:hasattachment" + (char)34 + "=1 AND " +
                // var Filter = "@SQL=" + (char)34 + "urn:schemas:httpmail:read" + (char)34 + "=0";
                Items.Restrict(Filter);
            }
            var result = new List <email>();

            foreach (var folderItem in Items)
            {
                Microsoft.Office.Interop.Outlook.MailItem mailItem = folderItem as Microsoft.Office.Interop.Outlook.MailItem;
                if (mailItem != null)
                {
                    var _e = new email(mailItem);
                    if (unreadonly)
                    {
                        if (_e.UnRead)
                        {
                            result.Add(_e);
                        }
                    }
                    else
                    {
                        result.Add(_e);
                    }
                }
            }
            Emails.Set(context, result);
            IEnumerator <email> _enum = result.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }
Beispiel #3
0
        protected override void StartLoop(NativeActivityContext context)
        {
            var folder     = Folder.Get(context);
            var maxresults = MaxResults.Get(context);
            var filter     = Filter.Get(context);

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }
            var outlookApplication = CreateOutlookInstance();

            if (outlookApplication.ActiveExplorer() == null)
            {
                Log.Warning("Outlook not running!");
                return;
            }
            MAPIFolder mfolder    = GetFolder(outlookApplication, folder);
            Items      Items      = mfolder.Items;
            var        unreadonly = UnreadOnly.Get(context);

            if (unreadonly)
            {
                if (string.IsNullOrEmpty(filter))
                {
                    filter = "";
                }
                if (string.IsNullOrEmpty(filter))
                {
                    filter = "[Unread]=true";
                }
                else
                {
                    filter += "and [Unread]=true";
                }
            }
            if (!string.IsNullOrEmpty(filter))
            {
                Items = Items.Restrict(filter);
            }
            var result = new List <email>();

            foreach (var folderItem in Items)
            {
                MailItem mailItem = folderItem as MailItem;
                if (mailItem != null)
                {
                    var _e = new email(mailItem);
                    result.Add(_e);
                    if (result.Count == maxresults)
                    {
                        break;
                    }
                }
            }
            Emails.Set(context, result);
            IEnumerator <email> _enum = result.ToList().GetEnumerator();

            context.SetValue(_elements, _enum);
            bool more = _enum.MoveNext();

            if (more)
            {
                IncIndex(context);
                SetTotal(context, result.Count);
                context.ScheduleAction(Body, _enum.Current, OnBodyComplete);
            }
        }