コード例 #1
0
        public static List <Program> PrepareData()
        {
            var           mails   = OutlookEmails.ReadMailItems();
            List <string> senders = new List <string>();

            List <string> domains      = new List <string>();
            List <int>    avgDurations = new List <int>();

            List <Program> listEmailDetailsfinal = new List <Program>();
            Program        emailDetailsfinal;


            foreach (var mail in mails)
            {
                senders.Add(mail.EmailFrom.ToString());
            }

            IEnumerable <string> unqSenders = senders.Distinct();


            foreach (string sender in unqSenders)
            {
                int cnt = 0;
                emailDetailsfinal = new Program();
                List <DateTime> dt        = new List <DateTime>();
                List <int>      durations = new List <int>();
                durations.Add(0);

                foreach (var ml in mails)
                {
                    if (ml.EmailFrom == sender)
                    {
                        dt.Add(ml.RecievedOn);
                        cnt += 1;
                    }
                }

                dt = SortAscending(dt);

                for (int a = 0; a < (dt.Count) - 1; a++)
                {
                    TimeSpan x        = dt[a + 1].Subtract(dt[a]);
                    var      duration = Convert.ToInt32(x.TotalMinutes / (1440));
                    durations.Add(duration);
                }

                emailDetailsfinal.EmailSender = sender;
                emailDetailsfinal.Counts      = cnt;
                emailDetailsfinal.freq        = Math.Round(durations.Average(), 0);
                listEmailDetailsfinal.Add(emailDetailsfinal);
            }

            return(listEmailDetailsfinal);
        }
コード例 #2
0
        public static List <OutlookEmails> ReadMailItems()

        {
            Application outlookapplication = null;
            NameSpace   outlookNamespace   = null;
            MAPIFolder  inboxFolder        = null;

            Items mailItems = null;
            List <OutlookEmails> listEmailDetails = new List <OutlookEmails>();
            OutlookEmails        emailDetails;

            try
            {
                outlookapplication = new Application();
                outlookNamespace   = outlookapplication.GetNamespace("MAPI");

                inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

                mailItems = inboxFolder.Items;
                ProgressBar pBar1 = new ProgressBar();
                pBar1.Minimum = 1;

                pBar1.Maximum = mailItems.Count;
                pBar1.Value   = 1;
                pBar1.Step    = 1;


                Form1 pbarForm = new Form1();
                pBar1.Width = 677;

                pbarForm.Controls.Add(pBar1);
                pbarForm.StartPosition = FormStartPosition.CenterScreen;
                pbarForm.Show();


                for (int j = 1; j < mailItems.Count; j++)

                {
                    emailDetails = new OutlookEmails();
                    emailDetails.EmailSubject = mailItems[j].Subject;
                    emailDetails.RecievedOn   = mailItems[j].ReceivedTime;
                    if (mailItems[j].senderEmailType == "EX")
                    {
                        emailDetails.EmailFrom = "xyz.de";
                    }
                    if (mailItems[j].senderEmailType == "SMTP")
                    {
                        string after = "@";
                        string x     = mailItems[j].SenderEmailAddress;
                        string final = x.Substring(x.LastIndexOf(after) + 1);
                        emailDetails.EmailFrom = final.ToLower();
                    }
                    listEmailDetails.Add(emailDetails);
                    pBar1.PerformStep();
                }
                System.Threading.Thread.Sleep(2);
                pbarForm.Close();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                ReleaseComObject(mailItems);
                ReleaseComObject(inboxFolder);
                ReleaseComObject(outlookNamespace);
                ReleaseComObject(outlookapplication);
            }
            return(listEmailDetails);
        }