コード例 #1
0
        public static ImapClient FromLoginInfo(string username, string password)
        {
            var imapClient = new ImapClient("imap.gmail.com", 993, true);

            if (!imapClient.Connection())
                throw new Exception("Could not connect!");
            if (!imapClient.LogIn(username, password))
                throw new Exception("Could not log in!");

            return imapClient;
        }
コード例 #2
0
        /// <summary>
        /// Searches the ac
        /// </summary>
        /// <param name="searchCriteria"></param>
        /// <param name="processMessages"></param>
        /// <returns></returns>
        public IEnumerable <IEmail> Search(EmailSearchCriteria searchCriteria, bool processMessages = true)
        {
            // create client
            var client = new ImapClient(_host, _port, _useSsl);

            // connect to host
            if (!client.Connection())
            {
                throw new ImapException(string.Format("Failed to connect to server {0}", _host));
            }

            // create result list
            var results = new List <IEmail>();

            try
            {
                // try to log in
                if (!client.LogIn(_userName, _password))
                {
                    throw new LogInException(_host, _userName);
                }

                // search either a single folder or all folders
                var folders = string.IsNullOrWhiteSpace(searchCriteria.Folder)
                                  ? (IEnumerable <Folder>)client.Folders
                                  : new[] { client.Folders[searchCriteria.Folder] };

                // search folders
                foreach (var folder in folders)
                {
                    // if folder is null, it was specified by name and not found
                    if (folder == null)
                    {
                        throw new FolderNotFoundException(_host, _userName, searchCriteria.Folder);
                    }

                    // add results of search
                    results.AddRange(SearchFolder(folder, searchCriteria));
                }

                // download messages if indicated
                if (processMessages)
                {
                    results.ForEach(m => m.Download());
                }
            }
            finally
            {
                // disconnect after search is done
                client.Disconnect();
            }

            return(results);
        }
コード例 #3
0
ファイル: ImapxSearcher.cs プロジェクト: piontec/bank2qif
        public MessageCollection FetchMessages(string host, string login, string pass, string imapQuery)
        {
            var client = new ImapClient(host, 993, true);

            client.Connection();
            client.LogIn(login, pass);

            var messages = client.Folders ["INBOX"].Search(imapQuery, false);

            foreach (var m in messages)
            {
                m.Process();
            }

            client.Disconnect();

            return(messages);
        }
コード例 #4
0
ファイル: ImapXManager.cs プロジェクト: CarlosVV/mediavf
        /// <summary>
        /// Searches the ac
        /// </summary>
        /// <param name="searchCriteria"></param>
        /// <param name="processMessages"></param>
        /// <returns></returns>
        public IEnumerable<IEmail> Search(EmailSearchCriteria searchCriteria, bool processMessages = true)
        {
            // create client
            var client = new ImapClient(_host, _port, _useSsl);

            // connect to host
            if (!client.Connection())
                throw new ImapException(string.Format("Failed to connect to server {0}", _host));

            // create result list
            var results = new List<IEmail>();

            try
            {
                // try to log in
                if (!client.LogIn(_userName, _password))
                    throw new LogInException(_host, _userName);

                // search either a single folder or all folders
                var folders = string.IsNullOrWhiteSpace(searchCriteria.Folder)
                                  ? (IEnumerable<Folder>)client.Folders
                                  : new[] {client.Folders[searchCriteria.Folder]};

                // search folders
                foreach (var folder in folders)
                {
                    // if folder is null, it was specified by name and not found
                    if (folder == null) throw new FolderNotFoundException(_host, _userName, searchCriteria.Folder);

                    // add results of search
                    results.AddRange(SearchFolder(folder, searchCriteria));
                }

                // download messages if indicated
                if (processMessages) results.ForEach(m => m.Download());
            }
            finally
            {
                // disconnect after search is done
                client.Disconnect();
            }

            return results;
        }
コード例 #5
0
        public IEnumerable<Mailbox> FetchMailboxes(ImapClient client, string username, string password)
        {
            IEnumerable<Mailbox> list = null;

            string retval = client.LogIn(username, password);

            if (string.IsNullOrEmpty(retval))
            {
                retval = client.FetchMailboxes(out list);
                if (string.IsNullOrEmpty(retval))
                {
                    list.ToList().Sort();
                }
            }
            client.LogOut();

            if (!string.IsNullOrEmpty(retval))
            {
                throw new Exception(retval);
            }
            return list;
        }
コード例 #6
0
        public IEnumerable <Mailbox> FetchMailboxes(ImapClient client, string username, string password)
        {
            IEnumerable <Mailbox> list = null;

            string retval = client.LogIn(username, password);

            if (string.IsNullOrEmpty(retval))
            {
                retval = client.FetchMailboxes(out list);
                if (string.IsNullOrEmpty(retval))
                {
                    list.ToList().Sort();
                }
            }
            client.LogOut();

            if (!string.IsNullOrEmpty(retval))
            {
                throw new Exception(retval);
            }
            return(list);
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: munr/iDeviceAppReporter
        private void ProcessEmails()
        {
            // using IMAPX library
            // http://hellowebapps.com/products/imapx/

            string username = txtUsername.Text;
            string password = txtPassword.Text;

            try
            {
                ImapClient client = new ImapClient(txtIMAPServer.Text, GetUserEnteredPort(), chkSSL.Checked);

                AddMessage("Initialized");

                bool result = client.Connection();

                if (result)
                {
                    AddMessage("Connected to server");
                }
                else
                {
                    AddMessage("Unable to connect to server");
                    return;
                }

                result = client.LogIn(username, password);

                if (!result)
                {
                    AddMessage("Unable to login. Check login details.");
                    return;
                }

                AddMessage("Logged in");

                Folder folder = client.Folders[txtFolder.Text];

                if (folder == null)
                {
                    AddMessage("Folder not found. Check folder name.");
                    return;
                }

                MessageCollection messageCollection = folder.Search("FROM \"iTunes Store\"", false);

                AddMessage("Found " + messageCollection.Count + " messages");

                AddMessage("***************************");

                int count = 0;

                foreach (Message message in messageCollection)
                {
                    if (m_Cancel)
                    {
                        AddMessage("Cancelled");
                        AddItemToSimpleRTB("\nCancelled");
                        return;
                    }

                    count++;

                    message.Process();

                    string from = "unknown";

                    if (message.From.Count > 0)
                        from = message.From[0].Address;

                    AddMessage("Processing Message " + count + " of " + messageCollection.Count + " : " + from + ", " + message.Subject);

                    ProcessMessage(count, message);
                }

                AddMessage("Done");

                UpdateStatusBar(string.Format("Finished processing {0} messages. Found {1} apps.  Total cost: ${2}", messageCollection.Count, m_AppCount, m_TotalCost.ToString("N2")));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }