Esempio n. 1
0
        public void WriteMailContact()
        {
            string       exceptionMes = string.Empty;
            Contact      mailContact  = new MailContact();
            Contact      standard     = new MailContact("Marichka", "*****@*****.**");
            StreamWriter streamWriter = new StreamWriter("../../MailContactOutput.txt");

            try
            {
                standard.Write(streamWriter);
                streamWriter.Close();
                streamWriter.Dispose();

                StreamReader streamReader = new StreamReader("../../MailContactOutput.txt");
                mailContact.Read(streamReader);
                streamReader.Close();
                streamReader.Dispose();
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(mailContact.Name, standard.Name);
            Assert.AreEqual(mailContact.Data, standard.Data);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
Esempio n. 2
0
        public static MailContact FormatToContacts(string str)
        {
            var contact = new MailContact();

            try
            {
                var pos1 = str.IndexOf('<');
                if (pos1 != -1)
                {
                    contact.DisplayName = str.Substring(0, pos1);
                }

                var pos2 = str.LastIndexOf('@');
                if (pos2 != -1)
                {
                    contact.UserName = str.Substring(pos1 + 1, pos2 - pos1 - 1);
                }

                contact.Host = str.Substring(pos2 + 1, str.Length - pos2 - 2);
            }
            catch (Exception)
            {
                MailCore.Common.Logger.Log.DebugFormat("Exception : Mail address '{0}' is invalid.", str);
            }

            return(contact);
        }
Esempio n. 3
0
        private void WriteResult()
        {
            TaskLogger.LogEnter();
            MailContact sendToPipeline = new MailContact(this.DataObject);

            base.WriteObject(sendToPipeline);
            TaskLogger.LogExit();
        }
Esempio n. 4
0
        public void MailContactEquels()
        {
            MailContact contact1 = new MailContact("Oleg", "oleg@mail");

            object      result = contact1.Clone();
            MailContact actual = (MailContact)result;

            Assert.AreEqual(contact1.name, actual.name);
        }
Esempio n. 5
0
        public MailContact GetMailContactBy(MimeMessage message)
        {
            if (_unassignedMailContact != null)
            {
                return(_unassignedMailContact);
            }

            return(_unassignedMailContact = _unitOfWork.MailContactRepository.TryGetBy(UnassignedMailContactGuid) ?? CreateUnassignedContact());
        }
        public void CompareToTestReturns1()
        {
            MailContact mailContact1 = new MailContact("natalia", "*****@*****.**");
            MailContact mailContact2 = new MailContact("anna", "*****@*****.**");

            int actual = mailContact1.CompareTo(mailContact2);

            Assert.AreEqual(actual, 1);
        }
Esempio n. 7
0
        public void MailComparator()
        {
            MailContact contact1 = new MailContact("Andrew", "andrew@");
            MailContact contact2 = new MailContact("Bodya", "Bodya@");
            int         expected = 1;

            int result = contact1.CompareTo(contact2);

            Assert.AreEqual(expected, result);
        }
Esempio n. 8
0
        protected override void WriteResult(ADObject result)
        {
            TaskLogger.LogEnter(new object[]
            {
                result.Identity
            });
            MailContact result2 = new MailContact((ADContact)result);

            base.WriteResult(result2);
            TaskLogger.LogExit();
        }
        public void ToStringTest()
        {
            const string name           = "natalia";
            const string mail           = "*****@*****.**";
            string       expectedResult = $"{name} - {mail}";
            MailContact  mailContact    = new MailContact(name, mail);

            string actual = mailContact.ToString();

            Assert.AreEqual(actual, expectedResult);
        }
        public void CompareToTestReturns0()
        {
            const string name         = "natalia";
            const string mail         = "*****@*****.**";
            MailContact  mailContact1 = new MailContact(name, mail);
            MailContact  mailContact2 = new MailContact(name, mail);

            int actual = mailContact1.CompareTo(mailContact2);

            Assert.AreEqual(actual, 0);
        }
        public void InputTestException()
        {
            const string name        = "sofia";
            const string mail        = "sofiagmail.com";
            const string data        = "sofia sofiagmail.com";
            MailContact  mailContact = new MailContact();

            mailContact.Input(data);

            Assert.AreEqual(mailContact.Name, name);
            Assert.AreEqual(mailContact.Info, mail);
        }
        public void CloneTest()
        {
            const string name        = "natalia";
            const string mail        = "*****@*****.**";
            MailContact  mailContact = new MailContact(name, mail);
            object       result      = mailContact.Clone();

            MailContact actual = (MailContact)result;

            Assert.IsNotNull(actual);
            Assert.AreEqual(name, actual.Name);
            Assert.AreEqual(mail, actual.Info);
        }
 public ActionResult Index(MailContact model)
 {
     if (ModelState.IsValid)
     {
         var body = new StringBuilder();
         body.AppendLine("Ad & Soyad: " + model.Name);
         body.AppendLine("E-Mail Adresi: " + model.Email);
         body.AppendLine("Konu: " + model.Subject);
         body.AppendLine("Mesaj: " + model.Message);
         Mail mail = new Mail();
         mail.MailSender(body.ToString(), model.Email);
     }
     return(View());
 }
Esempio n. 14
0
        public void TestMethodForClassMailContact()
        {
            MailContact  phone = new MailContact("Roman", "*****@*****.**");
            StreamWriter sw    = new StreamWriter("FileForTest.txt");

            phone.WrtiteToFile(sw);
            sw.Close();
            MailContact phone1 = new MailContact();

            using (StreamReader sr = new StreamReader("FileForTest.txt"))
            {
                phone1.ReadFromFile(sr);
            }
            Assert.IsTrue(phone1.Name == "Roman," && phone1.Email == "*****@*****.**" && phone.Name == "Roman" && phone.Email == "*****@*****.**");
        }
Esempio n. 15
0
        public void PropertiesMailContactInputIncorrectEmail()
        {
            Contact mailContact  = new MailContact();
            string  email        = "zakalic@@gmail.com";
            string  exceptionMes = string.Empty;

            try
            {
                mailContact.Data = email;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(mailContact.Data, string.Empty);
            Assert.AreNotEqual(exceptionMes, string.Empty);
        }
Esempio n. 16
0
        public void PropertiesMailContactInputIncorrectName()
        {
            Contact mailContact  = new MailContact();
            string  name         = "Vovik19";
            string  exceptionMes = string.Empty;

            try
            {
                mailContact.Name = name;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(mailContact.Name, string.Empty);
            Assert.AreNotEqual(exceptionMes, string.Empty);
        }
Esempio n. 17
0
        public void PropertiesMailContactInputCorrectData()
        {
            Contact mailContact  = new MailContact();
            string  name         = "Vovik";
            string  email        = "*****@*****.**";
            string  exceptionMes = string.Empty;

            try
            {
                mailContact.Name = name;
                mailContact.Data = email;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(mailContact.Name, name);
            Assert.AreEqual(mailContact.Data, email);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
        public void CloneListTest()
        {
            const string    name1        = "anna";
            const string    phone        = "2513529";
            PhoneContact    phoneContact = new PhoneContact(name1, phone);
            const string    name2        = "nazar";
            const string    mail         = "*****@*****.**";
            MailContact     mailContact  = new MailContact(name2, mail);
            List <IContact> result       = new List <IContact>();

            result.Add(phoneContact);
            result.Add(mailContact);
            Task task = new Task();

            List <IContact> actual = task.CloneList(result);

            Assert.AreEqual(name1, actual[0].Name);
            Assert.AreEqual(phone, actual[0].Info);
            Assert.AreEqual(name2, actual[1].Name);
            Assert.AreEqual(mail, actual[1].Info);
        }
Esempio n. 19
0
        public void sortList()
        {
            Contact[] arr = new Contact[5];
            arr[0] = new MailContact("bodya", "andrgmailcom");
            arr[1] = new MailContact("andrew", "bodgmailcom");
            arr[2] = new MailContact("marian", "mariangmailcom");
            arr[3] = new PhoneContact("vasyl", 234002340);
            arr[4] = new PhoneContact("oleg", 324823487);

            Contact[] expected = new Contact[5];
            arr[0] = new MailContact("andrew", "andrgmailcom");
            arr[1] = new MailContact("bodya", "bodgmailcom");
            arr[2] = new MailContact("marian", "mariangmailcom");
            arr[3] = new PhoneContact("oleg", 234002340);
            arr[4] = new PhoneContact("vasyl", 324823487);

            var sortedArray = arr.OrderBy(x => x.name).ToList();

            Array.Sort(arr);

            Assert.AreEqual(expected, arr);
        }
Esempio n. 20
0
        public void ReadMailContact()
        {
            string       exceptionMes = string.Empty;
            Contact      mailContact  = new MailContact();
            Contact      standard     = new MailContact("Andrii", "*****@*****.**");
            StreamReader stream       = new StreamReader("../../MailContactInput.txt");

            try
            {
                mailContact.Read(stream);
                stream.Close();
                stream.Dispose();
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(mailContact.Name, standard.Name);
            Assert.AreEqual(mailContact.Data, standard.Data);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
Esempio n. 21
0
    public bool Extract(NetworkCredential credential, out MailContactList list)
    {
        bool result = false;

        list = new MailContactList();

        DateTime jsStartDate = new DateTime(1970, 1, 1);
        TimeSpan endTs       = DateTime.Now.Subtract(jsStartDate);
        TimeSpan startTs     = DateTime.Now.AddMinutes(-2).Subtract(jsStartDate);

        try
        {
            CookieCollection cookies = new CookieCollection();

            // Prepare login form data
            HttpValueCollection loginFormValues = new HttpValueCollection();
            loginFormValues["Email"]      = credential.UserName;
            loginFormValues["Passwd"]     = credential.Password;
            loginFormValues["asts"]       = "";
            loginFormValues["continue"]   = ContinueUrl;
            loginFormValues["dsh"]        = "1461574034599761425";
            loginFormValues["hl"]         = "en";
            loginFormValues["ltmpl"]      = "default";
            loginFormValues["ltmplcache"] = "2";
            loginFormValues["rm"]         = "false";
            loginFormValues["rmShown"]    = "1";
            loginFormValues["service"]    = "mail";
            loginFormValues["signIn"]     = "Sign In";
            loginFormValues["scc"]        = "1";
            loginFormValues["ss"]         = "1";
            loginFormValues["GALX"]       = "rBTUs4OAJBI";
            loginFormValues["ltmpl"]      = "default";
            loginFormValues["ltmpl"]      = "default";

            // Convert to bytes
            byte[] loginPostData = Encoding.UTF8.GetBytes(loginFormValues.ToString(true));

            HttpWebRequest loginRequest = ( HttpWebRequest )WebRequest.Create(LoginUrl);
            loginRequest.Method            = "POST";
            loginRequest.UserAgent         = UserAgent;
            loginRequest.Referer           = LoginRefererUrl;
            loginRequest.ContentType       = "application/x-www-form-urlencoded";
            loginRequest.ContentLength     = loginPostData.Length;
            loginRequest.AllowAutoRedirect = false;

            // Create cookie container
            loginRequest.CookieContainer = new CookieContainer();
            loginRequest.CookieContainer.Add(new Cookie("GMAIL_LOGIN", "T" + startTs.Milliseconds.ToString() + "/" + startTs.Milliseconds.ToString() + "/" + endTs.Milliseconds.ToString(), "/", ".google.com"));
            loginRequest.CookieContainer.Add(new Cookie("GALX", "rBTUs4OAJBI", "/accounts", ".google.com"));

            // Add post data to request
            Stream stream;
            using (stream = loginRequest.GetRequestStream())
            {
                stream.Write(loginPostData, 0, loginPostData.Length);
            }

            HttpWebResponse loginResponse = ( HttpWebResponse )loginRequest.GetResponse();

            cookies.Add(loginResponse.Cookies);

            // Create request to export Google CSV page
            HttpWebRequest contactsRequest = ( HttpWebRequest )WebRequest.Create(ExportUrl);
            contactsRequest.Method    = "GET";
            contactsRequest.UserAgent = UserAgent;
            contactsRequest.Referer   = loginResponse.ResponseUri.ToString();

            // use cookie gotten from login page
            contactsRequest.CookieContainer = new CookieContainer();
            foreach (Cookie cookie in cookies)
            {
                contactsRequest.CookieContainer.Add(cookie);
            }

            HttpWebResponse exportResponse = ( HttpWebResponse )contactsRequest.GetResponse();

            // Read data from response stream
            string csvData;
            using (Stream responseStream = exportResponse.GetResponseStream())
            {
                using (StreamReader streamRead = new StreamReader(responseStream))
                {
                    csvData = streamRead.ReadToEnd();
                }
            }

            // parse google csv
            string[] lines = csvData.Split('\n');
            foreach (string line in lines)
            {
                string[] values = line.Split(',');
                if (values.Length < 2)
                {
                    continue;
                }

                MailContact mailContact = new MailContact();
                mailContact.Email = values[28];
                mailContact.Name  = values[0];
                if (mailContact.Email.Trim().Length > 0)
                {
                    list.Add(mailContact);
                }
            }

            result = true;
        }
        catch
        {
        }

        return(result);
    }
 // Token: 0x06000CD6 RID: 3286 RVA: 0x00027F2D File Offset: 0x0002612D
 public ContactIdParameter(MailContact contact) : base(contact.Id)
 {
 }
Esempio n. 23
0
 // Token: 0x06000D4B RID: 3403 RVA: 0x00028628 File Offset: 0x00026828
 public MailboxUserContactIdParameter(MailContact contact) : base(contact.Id)
 {
 }
Esempio n. 24
0
 /// <summary>
 /// Sends a message
 /// </summary>
 /// <param name="Message">The message to send</param>
 /// <param name="From">The sender (From: header)</param>
 /// <param name="To">The recipient (To: header)</param>
 public void Send(MailMessage Message, MailContact From, MailContact To)
 {
     this.Send(Message, From, new MailContact[] { To }, null, null);
 }
Esempio n. 25
0
        /// <summary>
        /// Sends a message
        /// </summary>
        /// <param name="Message">The message to send</param>
        /// <param name="From">The sender (From: header)</param>
        /// <param name="To">A list of recipients (To: header)</param>
        /// <param name="CC">A list of recipients (CC: header)</param>
        /// <param name="BCC">A list of recipients (in no header at all)</param>
        public void Send(MailMessage Message, MailContact From, MailContact[] To, MailContact[] CC = null, MailContact[] BCC = null)
        {
            // CC and BCC can be defined null
            if (CC == null)
            {
                CC = new MailContact[0];
            }
            if (BCC == null)
            {
                BCC = new MailContact[0];
            }
            // This array will be filled with all recipients
            string[] Recipients     = new string[To.Length + CC.Length + BCC.Length];
            int      RecipientIndex = 0;
            // Subject
            string MailHeaders = "Subject: " + Message.Subject + "\r\n";

            // From
            MailHeaders += "From: " + From.ToString() + "\r\n";
            // Reply-to
            MailHeaders += "Reply-to: <" + From.MailAddress + ">\r\n";
            // To
            MailHeaders += "To: ";
            for (int Counter = 0; Counter < To.Length; ++Counter)
            {
                MailHeaders += To[Counter].ToString() + ";";
                Recipients[RecipientIndex] = To[Counter].MailAddress;
                ++RecipientIndex;
            }
            MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            // BCC
            if (CC.Length != 0)
            {
                // CC
                MailHeaders += "CC: ";
                for (int Counter = 0; Counter < CC.Length; ++Counter)
                {
                    MailHeaders += CC[Counter].ToString() + ";";
                    Recipients[RecipientIndex] = CC[Counter].MailAddress;
                    ++RecipientIndex;
                }
                MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            }
            // BCC
            if (BCC.Length != 0)
            {
                for (int Counter = 0; Counter < BCC.Length; ++Counter)
                {
                    Recipients[RecipientIndex] = BCC[Counter].MailAddress;
                    ++RecipientIndex;
                }
            }
            // Date; below 2011, the date is probably not set and sending it will only give the message a higher spam score in spam filters
            if (DateTime.Now.Year > 2010)
            {
                MailHeaders += "Date: " + this._RFC2822_Date() + "\r\n";
            }
            // Message-ID
            MailHeaders += "Message-ID: <" + DateTime.Now.Ticks.ToString() + "@" + this._LocalHostname + ">\r\n";
            // Priority
            if (Message.Priority != 3)
            {
                MailHeaders += "X-Priority: " + Message.Priority.ToString() + "\r\n";
            }
            // Content Type
            MailHeaders += "Content-Type: " + Message.ContentType + "; charset=" + Message.CharacterSet + "\r\n";
            // Mailer
            MailHeaders += "X-Mailer: NETMFToolbox/0.1\r\n";

            // Actually sends the mail
            this._Send(From.MailAddress, Recipients, MailHeaders + "\r\n" + Message.Body);
        }
    public bool Extract(NetworkCredential credential, out MailContactList list)
    {
        bool result = false;

        list = new MailContactList();

        try
        {
            CookieCollection cookies = new CookieCollection();

            // Prepare login form data
            HttpValueCollection loginFormValues = new HttpValueCollection();
            loginFormValues["ltmpl"]            = "default";
            loginFormValues["ltmplcache"]       = "2";
            loginFormValues["continue"]         = ContinueUrl;
            loginFormValues["service"]          = "mail";
            loginFormValues["rm"]               = "false";
            loginFormValues["hl"]               = "en";
            loginFormValues["Email"]            = credential.UserName;
            loginFormValues["Passwd"]           = credential.Password;
            loginFormValues["PersistentCookie"] = "true";
            loginFormValues["rmShown"]          = "1";
            loginFormValues["null"]             = "Sign In";

            // Convert to bytes
            byte[] loginPostData = Encoding.UTF8.GetBytes(loginFormValues.ToString(true));

            HttpWebRequest loginRequest = ( HttpWebRequest )WebRequest.Create(LoginUrl);
            loginRequest.Method            = "POST";
            loginRequest.UserAgent         = UserAgent;
            loginRequest.Referer           = LoginRefererUrl;
            loginRequest.ContentType       = "application/x-www-form-urlencoded";
            loginRequest.ContentLength     = loginPostData.Length;
            loginRequest.AllowAutoRedirect = false;

            // Create cookie container
            loginRequest.CookieContainer = new CookieContainer();

            // Add post data to request
            Stream stream;
            using (stream = loginRequest.GetRequestStream())
            {
                stream.Write(loginPostData, 0, loginPostData.Length);
            }

            HttpWebResponse loginResponse = ( HttpWebResponse )loginRequest.GetResponse();

            cookies.Add(loginResponse.Cookies);

            // Create request to export Google CSV page
            HttpWebRequest contactsRequest = ( HttpWebRequest )WebRequest.Create(ExportUrl);
            contactsRequest.Method    = "GET";
            contactsRequest.UserAgent = UserAgent;
            contactsRequest.Referer   = loginResponse.ResponseUri.ToString();

            // use cookie gotten from login page
            contactsRequest.CookieContainer = new CookieContainer();
            foreach (Cookie cookie in cookies)
            {
                contactsRequest.CookieContainer.Add(cookie);
            }

            HttpWebResponse exportResponse = ( HttpWebResponse )contactsRequest.GetResponse();

            // Read data from response stream
            string csvData;
            using (Stream responseStream = exportResponse.GetResponseStream())
            {
                using (StreamReader streamRead = new StreamReader(responseStream))
                {
                    csvData = streamRead.ReadToEnd();
                }
            }

            // parse google csv
            string[] lines = csvData.Split('\n');
            foreach (string line in lines)
            {
                string[] values = line.Split(',');
                if (values.Length < 2)
                {
                    continue;
                }

                MailContact mailContact = new MailContact();
                mailContact.Email = values[1];
                mailContact.Name  = values[0];
                if (mailContact.Email.Trim().Length > 0)
                {
                    list.Add(mailContact);
                }
            }

            result = true;
        }
        catch
        {
        }

        return(result);
    }
Esempio n. 27
0
 protected override IConfigurable ConvertDataObjectToPresentationObject(IConfigurable dataObject)
 {
     return(MailContact.FromDataObject((ADContact)dataObject));
 }
Esempio n. 28
0
        /// <summary>
        /// Sends a message
        /// </summary>
        /// <param name="Message">The message to send</param>
        /// <param name="From">The sender (From: header)</param>
        /// <param name="To">A list of recipients (To: header)</param>
        /// <param name="CC">A list of recipients (CC: header)</param>
        /// <param name="BCC">A list of recipients (in no header at all)</param>
        public void Send(MailMessage Message, MailContact From, MailContact[] To, MailContact[] CC = null, MailContact[] BCC = null)
        {
            // CC and BCC can be defined null
            if (CC == null) CC = new MailContact[0];
            if (BCC == null) BCC = new MailContact[0];
            // This array will be filled with all recipients
            string[] Recipients = new string[To.Length + CC.Length + BCC.Length];
            int RecipientIndex = 0;
            // Subject
            string MailHeaders = "Subject: " + Message.Subject + "\r\n";
            // From
            MailHeaders += "From: " + From.ToString() + "\r\n";
            // Reply-to
            MailHeaders += "Reply-to: <" + From.MailAddress + ">\r\n";
            // To
            MailHeaders += "To: ";
            for (int Counter = 0; Counter < To.Length; ++Counter)
            {
                MailHeaders += To[Counter].ToString() + ";";
                Recipients[RecipientIndex] = To[Counter].MailAddress;
                ++RecipientIndex;
            }
            MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            // BCC
            if (CC.Length != 0)
            {
                // CC
                MailHeaders += "CC: ";
                for (int Counter = 0; Counter < CC.Length; ++Counter)
                {
                    MailHeaders += CC[Counter].ToString() + ";";
                    Recipients[RecipientIndex] = CC[Counter].MailAddress;
                    ++RecipientIndex;
                }
                MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            }
            // BCC
            if (BCC.Length != 0)
            {
                for (int Counter = 0; Counter < BCC.Length; ++Counter)
                {
                    Recipients[RecipientIndex] = BCC[Counter].MailAddress;
                    ++RecipientIndex;
                }
            }
            // Date; below 2011, the date is probably not set and sending it will only give the message a higher spam score in spam filters
            if (DateTime.Now.Year > 2010)
                MailHeaders += "Date: " + this._RFC2822_Date() + "\r\n";
            // Message-ID
            MailHeaders += "Message-ID: <" + DateTime.Now.Ticks.ToString() + "@" + this._LocalHostname + ">\r\n";
            // Priority
            if (Message.Priority != 3)
            {
                MailHeaders += "X-Priority: " + Message.Priority.ToString() + "\r\n";
            }
            // Content Type
            MailHeaders += "Content-Type: " + Message.ContentType + "; charset=" + Message.CharacterSet + "\r\n";
            // Mailer
            MailHeaders += "X-Mailer: NETMFToolbox/0.1\r\n";

            // Actually sends the mail
            this._Send(From.MailAddress, Recipients, MailHeaders + "\r\n" + Message.Body);
        }
Esempio n. 29
0
 // Token: 0x06000CE3 RID: 3299 RVA: 0x00027FD0 File Offset: 0x000261D0
 public UserContactComputerIdParameter(MailContact contact) : base(contact.Id)
 {
 }
Esempio n. 30
0
 /// <summary>
 /// Sends a message
 /// </summary>
 /// <param name="Message">The message to send</param>
 /// <param name="From">The sender (From: header)</param>
 /// <param name="To">The recipient (To: header)</param>
 public void Send(MailMessage Message, MailContact From, MailContact To)
 {
     this.Send(Message, From, new MailContact[] { To }, null, null);
 }
Esempio n. 31
0
 // Token: 0x06000B5A RID: 2906 RVA: 0x00024299 File Offset: 0x00022499
 public RecipientOrOrganizationIdParameter(MailContact mailContact)
 {
     this.RecipientParameter = new MailContactIdParameter(mailContact);
 }
Esempio n. 32
0
    public ArrayList Extract(string uname, string upass)
    {
        bool      result  = false;
        ArrayList myarray = new ArrayList();


        //list = New MailContactList()

        try
        {
            WebClient webClient = new WebClient();
            webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
            webClient.Encoding = Encoding.UTF8;

            byte[] firstResponse = webClient.DownloadData(_loginPage);
            string firstRes      = Encoding.UTF8.GetString(firstResponse);


            NameValueCollection postToLogin = new NameValueCollection();
            Regex regex = new Regex("type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\"", RegexOptions.IgnoreCase);
            Match match = regex.Match(firstRes);
            while (match.Success)
            {
                if (match.Groups[0].Value.Length > 0)
                {
                    postToLogin.Add(match.Groups[1].Value, match.Groups[2].Value);
                }
                match = regex.Match(firstRes, match.Index + match.Length);
            }


            postToLogin.Add(".save", "Sign In");
            postToLogin.Add(".persistent", "y");

            //Dim login As String = credential.UserName.Split("@"c)(0)
            string login = uname.Split('@').GetValue(0).ToString();

            postToLogin.Add("login", login);
            postToLogin.Add("passwd", upass);

            webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
            webClient.Headers[HttpRequestHeader.Referer]   = _loginPage;
            webClient.Encoding = Encoding.UTF8;
            webClient.Headers[HttpRequestHeader.Cookie] = webClient.ResponseHeaders[HttpResponseHeader.SetCookie];

            webClient.UploadValues(_authUrl, postToLogin);
            string cookie = webClient.ResponseHeaders[HttpResponseHeader.SetCookie];

            //If String.IsNullOrEmpty(cookie) Then
            //Return False
            //End If

            string   newCookie = string.Empty;
            string[] tmp1      = cookie.Split(',');
            foreach (string var in tmp1)
            {
                string[] tmp2 = var.Split(';');
                newCookie = (String.IsNullOrEmpty(newCookie) ? tmp2[0] : newCookie + ";" + tmp2[0]);
            }

            // set login cookie
            webClient.Headers[HttpRequestHeader.Cookie] = newCookie;
            byte[] thirdResponse = webClient.DownloadData(_addressBookUrl);
            string thirdRes      = Encoding.UTF8.GetString(thirdResponse);

            string crumb      = string.Empty;
            Regex  regexCrumb = new Regex("type=\"hidden\" name=\"\\.crumb\" id=\"crumb1\" value=\"(.*?)\"", RegexOptions.IgnoreCase);
            match = regexCrumb.Match(thirdRes);
            if (match.Success && match.Groups[0].Value.Length > 0)
            {
                crumb = match.Groups[1].Value;
            }


            NameValueCollection postDataAB = new NameValueCollection();
            postDataAB.Add(".crumb", crumb);
            postDataAB.Add("vcp", "import_export");
            postDataAB.Add("submit[action_export_yahoo]", "Export Now");

            webClient.Headers[HttpRequestHeader.UserAgent] = _userAgent;
            webClient.Headers[HttpRequestHeader.Referer]   = _addressBookUrl;

            byte[] FourResponse = webClient.UploadValues(_addressBookUrl, postDataAB);
            string csvData      = Encoding.UTF8.GetString(FourResponse);

            string[] lines = csvData.Split('\n');
            //Dim list1 As Hashtable()

            foreach (string line in lines)
            {
                string[] items = line.Split(',');
                if (items.Length < 5)
                {
                    continue;
                }
                string email = items[4];
                string name  = items[3];
                if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(name))
                {
                    email = email.Trim('"');
                    name  = name.Trim('"');
                    if (!email.Equals("Email") && !name.Equals("Nickname"))
                    {
                        MailContact mailContact = new MailContact();
                        mailContact.Name  = name;
                        mailContact.Email = email;
                        myarray.Add(email);
                        //list.Add(mailContact)
                    }
                }
            }

            result = true;
        }
        catch
        {
        }
        return(myarray);
    }