Exemplo n.º 1
0
 public MailBoxWindow(IMAPClient client)
 {
     m_client = client;
     m_view   = new MailBoxView(client);
     InitializeComponent();
     this.RootGrid.Children.Add(m_view);
     this.Show();
 }
Exemplo n.º 2
0
        public MainForm()
        {
            InitializeComponent();

            imap = new IMAPClient(settings.IMAPServer, settings.IMAPPort, settings.IMAPSSL);
            imap.Authenticate(settings.Username, settings.Password);

            UpdateFolders();
        }
Exemplo n.º 3
0
        public void OnSave(object parameter)
        {
            var        passwordBox = (PasswordBox)parameter;
            IMAPClient client      = new IMAPClient(DomainName);

            if (client.Connect(Username, passwordBox.Password))
            {
                MailBoxWindow mailBox = new MailBoxWindow(client);
                App.Current.MainWindow = mailBox;
            }
        }
Exemplo n.º 4
0
        public MailBoxViewModel(IMAPClient client)
        {
            m_IMAPClient = client;

            if (DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                return;
            }

            Inboxes = new ObservableCollection <EmailInbox>(client.GetInboxList());
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            LoginView view = this as LoginView;

            IMAPClient client = new IMAPClient(view.Domain.Text);

            if (client.Connect(view.Username.Text, passwordBox.Password))
            {
                MailBoxWindow mailBox = new MailBoxWindow(client);
                App.Current.MainWindow = mailBox;
            }
        }
Exemplo n.º 6
0
        public bool ServerLogin(string folder = null)
        {
            try
            {
                if (Server != null && Server.LoggedOn)
                {
                    return(true);
                }

                IMAPConfig config = new IMAPConfig(HostIMAP, PortIMAP, Email, Password, EnableSslIMAP, false, folder);
                IMAPClient client = new IMAPClient(config, null, 1);
                client.Logon();
                Server = client;

                return(true);
            }
            catch (Exception ex)
            {
                ex.ToOutput();
                return(false);
            }
        }
Exemplo n.º 7
0
        public async void Update(List <string> groupIDs)
        {
            try
            {
                IMAPClient client = new IMAPClient(imapConfig, null, 5);
                client.Logon();
                IMAPFolder folder = client.Folders[folderName];
                for (int i = 0; i < subFolderNames.Count; i++)
                {
                    folder = folder.SubFolders[i];
                    if (folder.FolderName == "Build_System")
                    {
                        break;
                    }
                }

                List <IMAPMessage> messages     = folder.Messages.OrderByDescending(msg => msg.Date).ToList();
                DateTime           lastPostDate = ReadLastPostedDateTime(cConfigurationFolderPath + cLastPostedBuildDateTimeFilePath);
                List <IMAPMessage> newMessages  = messages.TakeWhile((msg) => msg.Date > lastPostDate).ToList();

                if (newMessages.Count > 0)
                {
                    DateTime newestMessageDate = newMessages.Max((msg) => msg.Date);
                    bool     buildPosted       = await PostBuilds(newMessages, groupIDs);

                    if (buildPosted)
                    {
                        WriteLastPostedDateTime(cConfigurationFolderPath + cLastPostedBuildDateTimeFilePath, newestMessageDate);
                    }
                }
                client.Logoff();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in BSLogic.Update(): " + ex.Message);
            }
        }
Exemplo n.º 8
0
 public MailBoxView(IMAPClient client)
 {
     m_client         = client;
     this.DataContext = new MailBoxViewModel(client);
     InitializeComponent();
 }
        public async void Update(Dictionary <string, HashSet <string> > channelIDsForRepositories)
        {
            try
            {
                IMAPClient client = new IMAPClient(imapConfig, null, 5);
                client.Logon();
                IMAPFolder folder = client.Folders[folderName];
                for (int i = 0; i < folder.SubFolders.Count; i++)
                {
                    folder = folder.SubFolders[i];
                    if (folder.FolderName == "Commit_Notifications")
                    {
                        break;
                    }
                }

                List <IMAPMessage> messages        = folder.Messages.OrderByDescending(msg => msg.Date).ToList();
                DateTime           lastPostDate    = ReadLastPostedDateTime(cConfigurationFolderPath + cLastPostedCommitDateTimeFilePath);
                List <IMAPMessage> newImapMessages = messages.TakeWhile((msg) => msg.Date > lastPostDate).ToList();

                if (newImapMessages.Count > 0)
                {
                    newImapMessages.OrderBy(msg => msg.Date).Reverse();
                    HashSet <string> channelIDs = new HashSet <string>(channelIDsForRepositories.Values.SelectMany(c => c).ToList());
                    Dictionary <string, HashSet <string> > commitUidsPostedInChannel = new Dictionary <string, HashSet <string> >();
                    foreach (string channelID in channelIDs)
                    {
                        HashSet <string> commitUids = await getCommitUidsForChannel(channelID);

                        commitUidsPostedInChannel.Add(channelID, commitUids);
                    }

                    foreach (IMAPMessage imapMsg in newImapMessages)
                    {
                        string[] parts          = imapMsg.Subject.Split(':');
                        string   commitToPrefix = "Commit to ";
                        string   repositoryName = "";
                        if (parts[0].Length > commitToPrefix.Length)
                        {
                            repositoryName = parts[0].Substring(commitToPrefix.Length, parts[0].Length - commitToPrefix.Length);
                        }

                        bool             repositoryFound         = false;
                        HashSet <string> channelIDsForRepository = channelIDsForRepositories.TryGetValue(repositoryName, out repositoryFound);
                        if (repositoryFound)
                        {
                            bool postResult = await PostCommitToChannels(imapMsg, channelIDsForRepository, commitUidsPostedInChannel);

                            if (!postResult)
                            {
                                return;
                            }
                        }
                    }
                    DateTime newestMessageDate = newImapMessages.Max((msg) => msg.Date);
                    WriteLastPostedDateTime(cConfigurationFolderPath + cLastPostedCommitDateTimeFilePath, newestMessageDate);
                }
                client.Logoff();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception in CommitLogic.Update(): " + ex.Message);
            }
        }
Exemplo n.º 10
0
        static void IMAPTest()
        {
            //mailhose host = new mailhose
            //{
            //    server = "imap.163.com",
            //    Ssl = true,
            //    address = "*****@*****.**",
            //    password = "******",
            //    port = 993
            //};

            mailhost host = new mailhost
            {
                server   = "imap.126.com",
                Ssl      = false,
                address  = "*****@*****.**",
                password = "******",
                port     = 110
            };

            using (IMAPClient client = new IMAPClient())
            {
                client.Connect(host.server, host.port, host.Ssl);
                client.Login(host.address, host.password);
                var mailboxlist = client.ListMailbox();
                Console.WriteLine("邮箱列表:");
                Console.WriteLine(mailboxlist);

                client.SelectINBOX();
                MailHeadList list = client.GetMailHeads(SearchType.All);
                foreach (MailHeadModel mailheader in list)
                {
                    Console.WriteLine("UID: " + mailheader.UID);
                    Console.WriteLine("用户名: " + mailheader.Name);
                    Console.WriteLine("地址: " + mailheader.Address);
                    Console.WriteLine("主题: " + mailheader.Subject);
                    Console.WriteLine("日期: " + mailheader.Date.ToString("yyyy-MM-dd"));
                    Console.WriteLine();
                }

                var mailtest = client.GetMail(1);
                Console.WriteLine("UID: " + mailtest.MailHead.UID);
                Console.WriteLine("用户名: " + mailtest.MailHead.Name);
                Console.WriteLine("地址: " + mailtest.MailHead.Address);
                Console.WriteLine("主题: " + mailtest.MailHead.Subject);
                Console.WriteLine("日期: " + mailtest.MailHead.Date.ToString("yyyy-MM-dd"));
                Console.WriteLine("内容: " + mailtest.Body);
                Console.WriteLine();
                Console.WriteLine("超文本内容: " + mailtest.BodyHtml);
                Console.WriteLine("附件:");
                foreach (var item in mailtest.Attachments)
                {
                    //item.Download(@"E:\mailattachments");
                    Console.WriteLine(item.Name);
                }

                client.Disconnect();
                client.Dispose();
            }

            Console.ReadLine();
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            //IMAPConfig config = new IMAPConfig("<host>", "<username>", "<password>", false, true, "");
            //config.SaveConfig("settings.cfg");
            IMAPConfig config = new IMAPConfig(@"c:\test1.cfg");

            config.CacheFile = "";

            IMAPClient client = null;

            try
            {
                client = new IMAPClient(config, null, 5);
            }
            catch (IMAPException e)
            {
                Console.WriteLine(e.Message);
                return;
            }


            //IMAPFolder drafts = client.Folders["Drafts"];

            //IMAPMessage newMessage = new IMAPMessage();
            //newMessage.From.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.To.Add(new IMAPMailAddress("Jason Miesionczek", "*****@*****.**"));
            //newMessage.Date = DateTime.Now;
            //newMessage.Subject = "this is a new message";
            //drafts.AppendMessage(newMessage, "this is the content of the new message");
            //IMAPFolder f = client.Folders["INBOX"];
            //Console.WriteLine(f.Messages.Count);
            //IMAPMessage msg = f.GetMessageByID(21967);
            //Console.WriteLine(msg.TextData.Data);
            //foreach (IMAPFileAttachment attachment in msg.Attachments)
            //{
            //    attachment.SaveFile("C:\\");
            //}
            //Console.ReadLine();

            IMAPFolder f = client.Folders["INBOX"];

            int[] msgCount = null;

            while (msgCount.Length == 0)
            {
                msgCount = f.CheckForNewMessages();
                Thread.Sleep(1000);
            }

            foreach (int id in msgCount)
            {
                IMAPMessage msg = f.GetMessageByID(id);
                // do some logic here
                msg.MarkAsRead();
            }

            //IMAPFolder f = client.Folders["Deleted Items"];
            //IMAPMessage m = f.GetMessageByID(707);
            //IMAPFolder d = client.Folders["Deleted Items"];
            //IMAPMessage m = d.Messages[0];
            //IMAPMessage m = f.GetMessageByID(375);
            //IMAPMessage m = f.Messages[0];
            //m.RefreshData(true, true);

            //client._imap.ProcessMessageHeader(m, 0); // 2893
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessMessageHeader(m, 0);
            //client._imap.ProcessBodyStructure(m);
            //client._imap.ProcessBodyParts(m);
            //client._imap.ProcessAttachments(m);
            //IMAPSearchQuery query = new IMAPSearchQuery();
            //query.Range = new DateRange(DateTime.Now.AddDays(-6), DateTime.Now);
            //IMAPSearchResult sResult = f.Search(query);

            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchDateRange(DateTime.Now.AddDays(-6), DateTime.Now));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchFrom("Christine Fade", "*****@*****.**"));
            //IMAPSearchResult sResult = f.Search(IMAPSearchQuery.QuickSearchNew());

            //IMAPFolder test = f.SubFolders["Test"];
            //IMAPFolder del = client.Folders["Deleted Items"];
            //f.CopyMessageToFolder(f.Messages[0], test);
            //test.DeleteMessage(test.Messages[0]);
            //f.MoveMessageToFolder(f.Messages[0], test);

            //test.EmptyFolder();
            //Console.WriteLine("{0} - {1}", sResult.Query.Range.StartDate, sResult.Query.Range.EndDate);
            //foreach (IMAPMessage msg in sResult.Messages)
            //{
            //    msg.RefreshData(true, true, false);
            //    Console.WriteLine("{0}: {1}", msg.Date, msg.Subject);
            //    Console.WriteLine(msg.TextData.Data);
            //}
            //m.Attachments[1].SaveFile("C:\\");
            Console.ReadLine();
            foreach (IMAPMessage msg in client.Folders["INBOX"].Messages)
            {
                if (msg.BodyParts.Count == 0)
                {
                    Console.WriteLine(msg.Uid);
                }
            }
            client.Logoff();
        }