示例#1
0
 protected virtual OutlookItem SetSelected(OutlookItem item)
 {
     /*
      * this needs to be worked upon.
      * The problem is that although the item gets selected internally, yet it doesn't show up the same in the listview.
      */
     if (Explorer.CurrentFolder == Folder)
     {
         try
         {
             if (Explorer.Selection.Count > 0)
             {
                 var oldItem = this.Explorer.Selection[1];
                 this.Explorer.RemoveFromSelection(oldItem);
             }
             this.Explorer.AddToSelection(item.InnerObject);
         }
         catch (System.Exception ex)
         {
             // we can tolerate selection errors - they are bound to occur e.g. in conversation view.
             //if (!ex.Message.Contains("invalid for a conversation view"))
             //    System.Windows.Forms.MessageBox.Show(string.Format("Oops, an error occured: {0}\n{1}", ex.Message, Messages.CONTACT));
         }
     }
     this.Current = item;
     return(item);
 }
示例#2
0
        public virtual OutlookItem PreviousConversationItem()
        {
            var    items = AllItems;
            string currentCID;

            if (items[items.Count].EntryID != Current.EntryID)
            {
                if (!Current.TryGetPropertyValue("ConversationID", out currentCID))
                {
                    return(Previous());
                }

                int i;
                for (i = items.Count; i >= 1; i--)
                {
                    if (items[i].EntryID == Current.EntryID)
                    {
                        break;
                    }
                }

                int itemLen = items.Count;
                for (i++; i <= itemLen; i++)
                {
                    string thisCID;
                    var    item = new OutlookItem(items[i]);
                    if (item.TryGetPropertyValue("ConversationID", out thisCID) && currentCID == thisCID)
                    {
                        continue;
                    }
                    return(SetSelected(item));
                }
            }
            return(null);
        }
示例#3
0
        private void GetItemContent(OutlookItem item, out string header, out string body, string[] exclusions = null)
        {
            exclusions = exclusions ?? new string[0];
            switch (item.Class)
            {
            case OlObjectClass.olMail:
                GetMailHeaders((MailItem)item.InnerObject, out header, exclusions);
                body = ((MailItem)item.InnerObject).HTMLBody;
                break;

            case OlObjectClass.olMeetingRequest:
            case OlObjectClass.olMeetingCancellation:
            case OlObjectClass.olMeetingResponseNegative:
            case OlObjectClass.olMeetingResponsePositive:
            case OlObjectClass.olMeetingResponseTentative:
            case OlObjectClass.olMeetingForwardNotification:
                GetMeetingHeaders((MeetingItem)item.InnerObject, out header, exclusions);
                body = item.Body;
                break;

            default:
                GetOtherHeaders(item, out header, exclusions);
                body = item.Body;
                break;
            }
        }
示例#4
0
        private string GetItemHtmlForConversation(OutlookItem item)
        {
            string header, body;

            GetItemContent(item, out header, out body, new string[] { "title", "by" });
            string wrapStart = item.EntryID != mNavigator.Current.EntryID
                ? "<div>" : "<div role='region' aria-labelledby='mCurrent'><span id='mCurrent' style='display:none;'>Currently selected mail</span>";

            return(string.Format("{4}<h2 onclick=\"{0}\">{1}</h2><br/>{2}</div><br/><br/>{3}", GetTogglingJS(), ((dynamic)item.InnerObject).SenderName, header, body, wrapStart));
        }
示例#5
0
        private void CMAttachment_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            try
            {
                dynamic    obj   = CMAttachment.Tag;
                int        index = (int)obj.Index;
                Attachment attachment;
                if (InConversationView)
                {
                    using (var item = new OutlookItem(mNavigator.OutlookApp.Session.GetItemFromID(obj.ID)))
                    {
                        attachment = item.Attachments[index];
                    }
                }
                else
                {
                    attachment = mNavigator.Current.Attachments[index];
                }
                switch (e.ClickedItem.Name)
                {
                case "CMAOpen":
                    var tempFilePath = GetTempFilePath(attachment.FileName);
                    attachment.SaveAsFile(tempFilePath);
                    System.Diagnostics.Process.Start(tempFilePath);
                    break;

                case "CMASave":
                    saveFileDialog1.FileName = attachment.FileName;
                    if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        attachment.SaveAsFile(saveFileDialog1.FileName);
                    }
                    break;

                case "CMASaveAndOpen":
                    saveFileDialog1.FileName = attachment.FileName;
                    if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        attachment.SaveAsFile(saveFileDialog1.FileName);
                        System.Diagnostics.Process.Start(saveFileDialog1.FileName);
                    }
                    break;
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(attachment);
            }
            catch (System.Exception ex)
            {
                ExceptionHandler.Catch(ex);
            }
        }
示例#6
0
        private void GetOtherHeaders(OutlookItem item, out string smallHead, string[] exclusions)
        {
            StringBuilder header = new StringBuilder();

            if (!exclusions.Contains("title", StringComparer.OrdinalIgnoreCase))
            {
                header.Append("<p>");
                AppendTitle(item.InnerObject, header, false);
            }
            AddAttachments(header, item.Attachments);
            if (!exclusions.Contains("title", StringComparer.OrdinalIgnoreCase))
            {
                header.Append("</p>");
            }
            smallHead = header.ToString();
        }
示例#7
0
        private ConversationDTO GetRelatedItems(OutlookItem sourceItem, bool latestFirst, bool currentFolderOnly = true)
        {
            Conversation    c   = ((dynamic)sourceItem.InnerObject).GetConversation();
            ConversationDTO dto = new ConversationDTO()
            {
                Topic = sourceItem.ConversationTopic
            };
            var table = c.GetTable();

            if (table.GetRowCount() == 0)
            {
                dto.Items = new List <OutlookItem> {
                    sourceItem
                };
                dto.FirstRootItem = sourceItem;
            }
            else
            {
                table.MoveToStart();
                var row  = table.GetNextRow();
                var item = new OutlookItem(table.Session.GetItemFromID(row["EntryID"]));
                dto.FirstRootItem = item;
                SortedDictionary <DateTime, OutlookItem> ordered = new SortedDictionary <DateTime, OutlookItem>();
                while (true)
                {
                    if (!ordered.Values.Any(i => i.EntryID == item.EntryID) && (!currentFolderOnly || item.Parent.Name.Equals(Folder.Name, StringComparison.OrdinalIgnoreCase)))
                    {
                        DateTime sfield = item.TryGetPropertyValue("ReceivedTime", out sfield) ? sfield : item.LastModificationTime;
                        ordered.Add(sfield, item);
                    }
                    if (table.EndOfTable)
                    {
                        break;
                    }
                    row  = table.GetNextRow();
                    item = new OutlookItem(table.Session.GetItemFromID(row["EntryID"]));
                }
                var list = ordered.Values.ToList();
                if (latestFirst)
                {
                    list.Reverse();
                }
                dto.Items = list;
            }

            return(dto);
        }
示例#8
0
        public virtual OutlookItem NextConversationItem()
        {
            var    items = AllItems;
            string currentCID;

            // items are ordered in order from last to first.
            if (items[1].EntryID != Current.EntryID)
            {
                // if the current item is not a part of any conversation, then regular next would occur.
                if (!Current.TryGetPropertyValue("ConversationID", out currentCID))
                {
                    return(Next());
                }

                int i;
                for (i = items.Count; i >= 1; i--)
                {
                    if (items[i].EntryID == Current.EntryID)
                    {
                        break;
                    }
                }

                for (i--; i >= 1; i--)
                {
                    string thisCID;
                    var    item = new OutlookItem(items[i]);
                    if (item.TryGetPropertyValue("ConversationID", out thisCID) && currentCID == thisCID)
                    {
                        continue;
                    }
                    return(SetSelected(item));
                }
            }
            return(null);
        }