Exemplo n.º 1
0
		public static void ScanDir(string[] strings, string[] args)
		{
			if (args.Length == 0)
			{
				//args = new string[] { @"C:\EMLs" };
				throw new Exception("first argumant should be directory to scan...");
			}
			Console.WriteLine("Getting files...");
			string[] fileEntries = Directory.GetFiles(args[0]);
			Console.WriteLine("Got " + fileEntries.Length.ToString("#,##0") + " files...");
			int left = 0;
			int exceptions = 0;
			int i = 0;
			int ignored = 0;
			int ignoredHard = 0;
			int hardBounces = 0;

			Bounce b = new Bounce();
			b.UnlockComponent("DONTSTAYINBOUNCE_OS2MBg0e7GpB");

			foreach (string fileName in fileEntries)
			{
				try
				{
					b.ExamineEml(fileName);

					dealWithBounce(strings, b, fileName, ref hardBounces, ref ignoredHard, ref ignored);
				}
				catch (Exception ex)
				{
					exceptions++;
				}
				
				i++;
				if (i % 100 == 0)
					Console.WriteLine("Processed: " + i.ToString("#,##0") + " / " + fileEntries.Length.ToString("#,##0") + ", hardBounces: " + hardBounces.ToString("#,##0") + ", ignoredHard: " + ignoredHard.ToString("#,##0") + ", ignored: " + ignored.ToString("#,##0") + ", errors: " + exceptions.ToString("#,##0"));

			}
		}
Exemplo n.º 2
0
		public static void ScanGmail(string[] strings, Types type)
		{
			Console.WriteLine("VER 3");
			Bounce b = new Bounce();
			b.UnlockComponent("DONTSTAYINBOUNCE_OS2MBg0e7GpB");

			MailMan mailman = new MailMan();
			mailman.UnlockComponent("DONTSTAYINMAILQ_5CHEZpZc7Gp9");
			//mailman.ConnectTimeout = 5;
			mailman.MailPort = 995;
			mailman.PopSsl = true;
			mailman.MailHost = "pop.gmail.com";
			if (type == Types.DontStayIn)
			{
				Console.WriteLine("*****@*****.**");
				mailman.PopUsername = "******";
				mailman.PopPassword = "******";
			}
			else if (type == Types.Mixmag)
			{
				Console.WriteLine("*****@*****.**");
				mailman.PopUsername = "******";
				mailman.PopPassword = "******";
			}
			else if (type == Types.SpamTrap)
			{
				Console.WriteLine("*****@*****.**");
				mailman.PopUsername = "******";
				mailman.PopPassword = "******";
			}
			// Copy the mail into a bundle object.  The mail still remains
			// on the POP3 server.  Call TransferMail to copy and remove
			// mail from the POP3 server.
			Chilkat.EmailBundle bundle;

			Console.WriteLine("Getting bundle...");

			List<string> emailAddresses = new List<string>();
			int ignored = 0;
			int ignoredHard = 0;
			int hardBounces = 0;
			int exceptions = 0;
			int total = 0;

			// Loop over each email and save attachments.
			// Also add the email subject to a list box.

			do
			{

				emailAddresses = new List<string>();
				ignored = 0;
				ignoredHard = 0;
				hardBounces = 0;
				exceptions = 0;
				total = 0;

				bundle = mailman.CopyMail();
				Console.WriteLine("Got {0} messages", bundle.MessageCount.ToString());

				total = bundle.MessageCount;
				int i;
				for (i = 0; i < bundle.MessageCount; i++)
				{
					Chilkat.Email email = bundle.GetEmail(i);

					try
					{
						Console.Write(".");
						if (type == Types.SpamTrap)
						{
							#region spam trap
							if (email.Subject == "complaint about message from 84.45.14.32")
							{
								bool isEflyer = false;
								bool isUpdateEmail = false;
								string fullBody = email.Body;
								string recipient = "";
								string subject = "";

								//Console.WriteLine(fullBody.Length > 4096 ? fullBody.Substring(0, 4096) : fullBody);
								//Console.ReadLine();

								if (fullBody.IndexOf("From: [email protected]\r", StringComparison.OrdinalIgnoreCase) == -1)
								{
									isEflyer = true;
								}

								if (fullBody.IndexOf("Subject: DontStayIn this week", StringComparison.OrdinalIgnoreCase) > -1 ||
									fullBody.IndexOf("Subject: Don't Stay In this week", StringComparison.OrdinalIgnoreCase) > -1)
								{
									isUpdateEmail = true;
								}

								{
									string firstLine = fullBody.Substring(0, fullBody.IndexOf("\r"));
									recipient = firstLine.Substring(firstLine.IndexOf(" ") + 1);
								}

								{
									string subjectAndOn = fullBody.Substring(fullBody.IndexOf("\r\nSubject: ", StringComparison.OrdinalIgnoreCase) + 11);
									subject = subjectAndOn.Substring(0, subjectAndOn.IndexOf("\r"));
								}

								Console.WriteLine("Email: {0}, Eflyer: {1}, UpdateEmail: {2}, Subject: {3}", recipient, isEflyer, isUpdateEmail, subject.Length > 30 ? subject.Substring(0,30) : subject);

								UsrSet us = new UsrSet(new Query(new Q(Usr.Columns.Email, recipient)));
								if (us.Count > 0)
								{
									foreach (Usr u in us)
									{
										if (isEflyer)
										{
											u.SendFlyers = false;
										}
										else if (isUpdateEmail)
										{
											u.SendSpottedEmails = false;
										}
										else
										{
											u.EmailHold = true;
										}
										u.Update();
									}
								}

							}
							else
								Console.WriteLine("(not complaint email)");
							#endregion
						}
						else
						{
							b.ExamineEmail(email);
							dealWithBounce(strings, b, "", ref hardBounces, ref ignoredHard, ref ignored);
						}
						
					}
					catch (Exception ex)
					{
						Console.WriteLine("EXCEPTION");
						//Console.WriteLine(ex.Message);
						//throw ex;
						exceptions++;
					}
					//Console.WriteLine("");
					
					//if (i < 10 || i % 10 == 0)
					//	Console.WriteLine("Processed: " + i.ToString("#,##0") + " / " + total.ToString("#,##0") + ", bounces: " + hardBounces.ToString("#,##0") + ", ignored: " + ignored.ToString("#,##0") + ", ignoredHard: " + ignoredHard.ToString("#,##0") + ", errors: " + exceptions.ToString("#,##0"));


				}
			}
			while (total >= 250);
			
		}