예제 #1
0
 public ImapAccountControl(ImapAccount account)
 {
     InitializeComponent();
     _account     = account;
     _dataContext = new ImapAccountDataContext(_account, RemoveImapMailboxFunction);
     DataContext  = _dataContext;
 }
예제 #2
0
 private void AddAccountClick(object sender, RoutedEventArgs e)
 {
     if (SourceComboBox.SelectedItem != null)
     {
         IMailAccount account = null;
         if ("Imap".Equals(((ComboBoxItem)(SourceComboBox.SelectedItem)).Content))
         {
             account = new ImapAccount();
         }
         else if ("Mbox".Equals(((ComboBoxItem)(SourceComboBox.SelectedItem)).Content))
         {
             account = new MboxAccount();
         }
         else if ("Exchange".Equals(((ComboBoxItem)(SourceComboBox.SelectedItem)).Content))
         {
             account = new ExchangeAccount();
         }
         else
         {
             Logger.Warn("Unsupported Account '" + ((ComboBoxItem)(SourceComboBox.SelectedItem)).Content + "'");
         }
         if (account != null)
         {
             account.AddedMailbox   += AddMailboxEvent;
             account.RemovedMailbox += RemoveMailboxEvent;
             MailSources.Add(account);
         }
     }
 }
예제 #3
0
 public ImapAccountDataContext(ImapAccount account, Action <AuthenticatedMailbox> removeMailboxAction)
 {
     _account = account;
     // ImapMailboxes = new ObservableCollection<ImapMailbox>();
     //ImapMailboxes.CollectionChanged += (sender, args) => OnPropertyChanged("ImapMailboxes");
     Mailboxes = new AuthenticatedMailboxList(removeMailboxAction, Dispatcher.CurrentDispatcher);
     Mailboxes.SetList(account.Mailboxes.UnderlyingCollection);
     Mailboxes.CollectionChanged += (sender, args) => OnPropertyChanged("Mailboxes");
 }
예제 #4
0
        /// <summary>
        /// Get all new emails since the supplied uid
        /// </summary>
        /// <param name="account">The account to be checked</param>
        /// <returns>List of messages</returns>
        public static List <MessageInfo> GetNewMessages(ImapAccount account)
        {
            try
            {
                // We create Imap client
                using (var imap = new Imap4Client())
                {
                    imap.ConnectSsl(account.Host);

                    // Login to mail box
                    imap.Login(account.UserName, account.Password);

                    var inbox = imap.SelectMailbox("inbox");

                    // Fetching new messages
                    // For newly configured accounts, we fetch only unread messages for the first time. After that
                    // we look for new messaged whether or not they are read.
                    var searchQuery = account.LastUid <= 0
                        ? "UNSEEN"
                        : "ALL"; // should be string.Format("UID {0}:*", account.LastUid + 1); but my server don't support it

                    return(inbox.Search(searchQuery)
                           //.Where(uid => inbox.Fetch.Uid(uid) > account.LastUid)    // Since my email server don't support SEARCH UID x:*
                           .Where(uid => uid > account.LastUid) // TODO: This or previous line depending or if your email server support SEARCH UID x:* or not
                           .Select(m =>
                    {
                        var msg = new MessageInfo(account)
                        {
                            MessageUid = inbox.Fetch.Uid(m)
                        };

                        var header = inbox.Fetch.HeaderObject(m);
                        msg.MessageDate = header.ReceivedDate;
                        msg.Subject = header.Subject;
                        msg.From = string.IsNullOrWhiteSpace(header.From.Name) ? header.From.Email : header.From.Name;

                        return msg;
                    })
                           .ToList());
                }
            }
            catch (Exception)
            {
                return(new List <MessageInfo>()); // In general we get connection errors
            }
        }
예제 #5
0
 internal MessageInfo(ImapAccount imapAccount)
 {
     ImapAccountId = imapAccount.Id;
     MailBoxName   = imapAccount.AccountName;
 }