예제 #1
0
        /// <summary>
        /// Converts (parts of) MessageSummary to MailHeader
        /// </summary>
        /// <param name="msgSum"></param>
        /// <returns></returns>
        public static MailHeader ConvertMessageSummary(MessageSummary msgSum)
        {
            var mailHeader = new MailHeader();

            mailHeader.Subject = msgSum.Envelope.Subject;

            InternetAddressList fromList = msgSum.Envelope.From;
            string fromString            = "";

            //For all InternetAddresses in InternetAddressList, add display name (if it exists)
            //to the fromString, otherwise add email address
            foreach (var from in fromList)
            {
                if (string.IsNullOrEmpty(from.Name))
                {
                    if (fromList.Count > 1)
                    {
                        fromString = from.ToString() + "," + fromString;
                    }
                    else
                    {
                        fromString = from.ToString();
                    }
                }
                else
                {
                    if (fromList.Count > 1)
                    {
                        fromString = from.Name + "," + fromString;
                    }
                    else
                    {
                        fromString = from.Name;
                    }
                }
            }

            mailHeader.From = fromString;

            string date = "";

            //If the message´s date is today - set date string to Hour+Minute only. Otherwise set to full date&time
            if (msgSum.Date.Day == DateTimeOffset.Now.Day)
            {
                date = msgSum.Date.Hour + ":" + msgSum.Date.Minute;
            }
            else
            {
                string format = "yyyy-MM-dd HH:mm";

                //Formats the date to swedish culture
                date = msgSum.Date.ToString(format, new CultureInfo("sv-SE"));
            }

            mailHeader.Date     = date;
            mailHeader.UniqueId = msgSum.UniqueId;

            return(mailHeader);
        }
예제 #2
0
        /// <summary>
        /// Handles event when user clicks the listview - sets the clicked mail´s content to the webview&listview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MailListView_ItemClicked(object sender, ItemClickEventArgs e)
        {
            AttachedFileList.Clear();

            MailHeader msg = (MailHeader)e.ClickedItem;

            CurrentMessage = MailHandler.GetSpecificMail(msg.UniqueId);
            HandleAttachmentsAsync(CurrentMessage);
            SetContent(CurrentMessage);
        }
예제 #3
0
        /// <summary>
        /// Gets mail headers
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <returns></returns>
        public static ObservableCollection <MailHeader> GetMailHeaders(string searchTerm)
        {
            ObservableCollection <MailHeader> headerList = new ObservableCollection <MailHeader>();

            if (LoggedIn)
            {
                var inbox = client.Inbox;
                inbox.Open(FolderAccess.ReadWrite);

                //Debug.WriteLine("Total messages: {0}", inbox.Count);

                var orderBy = new[] { OrderBy.ReverseArrival };

                List <IMessageSummary> msgList = null;

                //If the searchTerm isnt null or empty, search for messages matching the searchterm and sort them
                //in reverse arrival order
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    //Search query
                    var query = (SearchQuery.SubjectContains(searchTerm)).Or(SearchQuery.BodyContains(searchTerm));

                    //Searches the mail folder using the query
                    var uidList = inbox.Search(query);

                    if (uidList.Count != 0)
                    {
                        //Fetches the messagesummaries of uidList
                        msgList = inbox.Fetch(uidList, MessageSummaryItems.Envelope | MessageSummaryItems.UniqueId).ToList();

                        //Sorts msgList in reverse arrival sort order
                        MessageSorter.Sort(msgList, orderBy);

                        isMailSearchSuccess = true;
                    }
                    else
                    {
                        isMailSearchSuccess = false;
                        return(null);
                    }
                }
                //If the searchTerm is null or empty, fetch all messagesummaries and sort them in
                //reverse arrival order
                else
                {
                    //Fetches all messagesummaries
                    msgList = inbox.Fetch(0, -1, MessageSummaryItems.Envelope | MessageSummaryItems.UniqueId).ToList();

                    if (msgList.Count != 0)
                    {
                        //Sorts msgList in reverse arrival sort order
                        MessageSorter.Sort(msgList, orderBy);
                    }
                    else
                    {
                        return(null);
                    }
                }

                foreach (MessageSummary summary in msgList)
                {
                    MailHeader mailHeader = ConvertMessageSummary(summary);
                    headerList.Add(mailHeader);
                }
            }
            else
            {
                if (Login())
                {
                    GetMailHeaders(searchTerm);
                }
            }
            return(headerList);
        }