Example #1
0
 public ImapX.Message GetMailBySubject(string subject)
 {
     ImapX.Message output = null;
     if (!_client.IsConnected)
     {
         if (!_client.Connect())
         {
             return(output);
         }
         if (!_client.Login(_login, _password))
         {
             return(output);
         }
     }
     ImapX.Message[] messages = _client.Folders.Inbox.Search("UNSEEN", ImapX.Enums.MessageFetchMode.Headers); // THIS LINE takes like 5-10 seconds to complete
     foreach (var item in messages)
     {
         if (item.Subject.Contains(subject))
         {
             item.Download(ImapX.Enums.MessageFetchMode.Body);
             output = item;
             break;
         }
     }
     return(output);
 }
Example #2
0
 bool auth(ImapX.Message x, IExcelDataReader excelReader)
 {
     while (excelReader.Read())
     {
         if (excelReader.GetString(0) == x.From.Address)
         {
             return(true);
         }
     }
     return(false);
 }
Example #3
0
 public Write_Email(ImapX.Message message, string mode)
 {
     InitializeComponent();
     if (mode == "Reply")
     {
         to.Text      = message.From.Address;
         subject.Text = message.Subject;
         body.Text    = message.Body.Text;
     }
     else
     {
         subject.Text = message.Subject;
         body.Text    = message.Body.Text;
     }
 }
Example #4
0
        private static void WriteToExcel(ImapX.Message message)
        {
            OleDbConnection conn = new OleDbConnection();

            conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path.Combine(@"H:\Users\denis\Documents\Visual Studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug", "emails.xlsx") + ";" +
                                    "Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=0;MAXSCANROWS=0'";
            conn.Open();
            OleDbCommand cmd = new OleDbCommand();

            cmd.Connection = conn;
            string sheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null)?.Rows[0]["TABLE_NAME"].ToString();

            cmd.CommandText = $"INSERT INTO [{sheet}] ([Date], [Email], [Subject], [City]) VALUES('{message.Date}', '{message.From.Address}', '{message.Subject}', '{message.Body.Text}')";
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public bool MarquerCommeLu(EnvoyerMail.MailRecu m)
        {
            bool res = false;

            var client = new ImapClient("imap.gmail.com", true);

            if (client.Connect())
            {
                if (client.Login(user, motDePasse))
                {
                    ImapX.Message tmp = client.Folders.Inbox.Search(string.Concat("UID ", m.Uid)).First();
                    tmp.Seen = true;
                    res      = true;
                }
            }

            client.Logout();

            return(res);
        }
Example #6
0
        private void ProcessMessage(int number, Message message)
        {
            // Get the email text body
            string messageBody = message.TextBody.TextData;

            // Replace any =\n with spaces.  This is some weird formatting that
            // happens in a few random emails fro no apparent reason
            messageBody = messageBody.Replace("=" + Environment.NewLine, string.Empty);

            // Get the message header
            MessageHeader header = MessageHeader.Get(message);

            if (string.IsNullOrEmpty(header.ReceiptNumber) && string.IsNullOrEmpty(header.OrderNumber))
                return;

            // Parse the message and get the app item lines
            IEnumerable<string> itemLines = GetItemLines(messageBody);

            foreach (string itemLine in itemLines)
                AddItemToSimpleRTB(itemLine + Environment.NewLine);

            int count = 0;

            foreach (string itemLine in itemLines)
            {
                string line = itemLine;

                if (line.EndsWith("Free"))
                    line = line.Substring(0, itemLine.Length - 4) + "$0.00";

                m_AppCount++;
                m_TotalCost += GetPrice(itemLine);

                UpdateStatusBar(string.Format("Found {0} apps... Cost: ${1}", m_AppCount, m_TotalCost.ToString("N2")));

                // Parse the line
                Match match = Regex.Match(line, @"(?<ItemCode>[^\s\s]+)\s+(?<AppName>[^,]+),\sv(?<AppVersion>[0-9A-Za-z\.]+),\sSeller:\s{2,}(?<Seller>[^$]+)(?<Price>[$\d\.\D]+)");

                // Get matched values
                string appName = match.Groups["AppName"].Value.Trim();
                string appVersion = match.Groups["AppVersion"].Value.Trim();
                string appSeller = match.Groups["Seller"].Value.Trim();
                string appPrice = match.Groups["Price"].Value.Trim();

                // Hacky workaround, default app name to line if no match
                if (!match.Success)
                    appName = line.Substring(line.IndexOf(" ")).Trim();

                var o = new AppInfo
                            {
                                MessageNumber = number,
                                AppNumber = m_AppCount,

                                AppName = appName,
                                AppVersion = appVersion,
                                AppSeller = appSeller,
                                AppPrice = appPrice,

                                ReceiptNumber = header.ReceiptNumber,
                                OrderNumber = header.OrderNumber,
                                ReceiptDate = header.ReceiptDate,
                                OrderTotal = header.OrderTotal,
                                BilledTo = header.BilledTo
                            };

                m_AppInfo.Add(o);

                count++;
            }

            AddMessage("Found " + count + " apps");
        }