public static long FeedBackIns(MessageInfo message) { using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlDataAdapter("FeedBackQueueInsReceivedCRM", conn)) { var body = message.Mail.FindFirstPlainTextVersion() == null ? message.Mail.FindFirstHtmlVersion().GetBodyAsText() : message.Mail.FindFirstPlainTextVersion().GetBodyAsText(); var bodyEnc = message.Mail.FindFirstPlainTextVersion() == null ? message.Mail.FindFirstHtmlVersion().BodyEncoding.EncodingName : message.Mail.FindFirstPlainTextVersion().BodyEncoding.EncodingName; var outId = new SqlParameter("@ID", SqlDbType.BigInt) { Direction = ParameterDirection.Output }; cmd.SelectCommand.CommandType = CommandType.StoredProcedure; cmd.SelectCommand.Parameters.Add(new SqlParameter("@Date", message.Mail.Headers.DateSent)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressTo", message.Mail.Headers.To[0].Address ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressFrom", message.Mail.Headers.From.Address ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@NameFrom", message.Mail.Headers.From.DisplayName ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Subject", message.Mail.Headers.Subject ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@MessageID", message.Mail.Headers.MessageId ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Body", body ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@CharSet", bodyEnc ?? "")); cmd.SelectCommand.Parameters.Add(outId); conn.Open(); cmd.SelectCommand.ExecuteNonQuery(); return outId.Value as long? ?? 0; } }
// ReSharper disable once InconsistentNaming public static long FBLAdd(MessageInfo message) { using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlDataAdapter("FBLAdd", conn)) { var outId = new SqlParameter("@ID", SqlDbType.BigInt) { Direction = ParameterDirection.Output }; cmd.SelectCommand.CommandType = CommandType.StoredProcedure; cmd.SelectCommand.Parameters.Add(new SqlParameter("@DateRecieved", DateTime.Now)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Subject", message.Mail.Headers.Subject ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@MessageID", message.Mail.Headers.MessageId ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressTo", message.Mail.Headers.To[0].Address ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressFrom", message.Mail.Headers.From.Address ?? "")); // TODO: Fill params when FBL will be configured cmd.SelectCommand.Parameters.Add(new SqlParameter("@SourceIP", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AuthResult", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@FeedBackType", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@OriginalRcptTo", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@OriginalSubject", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@OriginalMailFrom", DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@RawMessage", message.Mail.RawMessage)); cmd.SelectCommand.Parameters.Add(outId); conn.Open(); cmd.SelectCommand.ExecuteNonQuery(); return outId.Value as long? ?? 0; } }
public static long BounceAdd(MessageInfo message) { using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlDataAdapter("BounceAdd", conn)) { var body = message.Mail.FindFirstPlainTextVersion() == null ? message.Mail.FindFirstHtmlVersion().GetBodyAsText() : message.Mail.FindFirstPlainTextVersion().GetBodyAsText(); var outId = new SqlParameter("@ID", SqlDbType.BigInt) { Direction = ParameterDirection.Output }; cmd.SelectCommand.CommandType = CommandType.StoredProcedure; cmd.SelectCommand.Parameters.Add(new SqlParameter("@RawMessage", message.Mail.RawMessage)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Message", body)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@Subject", message.Mail.Headers.Subject ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@MessageID", message.Mail.Headers.MessageId ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressTo", message.Mail.Headers.To[0].Address ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@AddressFrom", message.Mail.Headers.From.Address ?? "")); cmd.SelectCommand.Parameters.Add(new SqlParameter("@DateRecieved", DateTime.Now)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@BounceTypeSysName", (object)message.Subtype ?? DBNull.Value)); cmd.SelectCommand.Parameters.Add(new SqlParameter("@SourceFrom", (object)message.Recipient ?? DBNull.Value)); // TODO: Add ListId support cmd.SelectCommand.Parameters.Add(new SqlParameter("@ListId", DBNull.Value)); cmd.SelectCommand.Parameters.Add(outId); conn.Open(); cmd.SelectCommand.ExecuteNonQuery(); return outId.Value as long? ?? 0; } }
public static void SaveEntireMessage(MessageInfo message) { //Save FeedBack var id = FeedBackIns(message); if (id <= 0) throw new Exception(String.Format("FeedBack insert failed of message '{0}'. [FeedBackQueueInsReceived] returned {1}", message.Mail.Headers.MessageId, id)); if (message.Mail.FindAllAttachments().Count == 0) return; //Save attachments foreach (var attach in message.Mail.FindAllAttachments()) FeedBackAttachIns(id, attach.FileName, attach.Body); }
private MessageInfo FilterSpam(MessageInfo mail) { //TODO: Add SpamAssassin logic return(mail); }
private void GetMails(MailboxInfo info) { try { using (var client = new Pop3Client()) { //Get Zabbix metrics var stopwatch = new Stopwatch(); stopwatch.Start(); //Get mail count client.Connect(info.Hostname, info.Port, false); client.Authenticate(info.User, info.Password); stopwatch.Stop(); //Send it to Zabbix Functions.Zabbix.SendData(new ZabbixItem { Host = _config.HostKey, Key = info.Type + _config.TimingKey, Value = stopwatch.ElapsedMilliseconds.ToString() }); Functions.Log.Debug("Send [{0}] timing to Zabbix: connected to '{1}' as '{2}', timing {3}ms", info.Type, info.Hostname, info.User, stopwatch.ElapsedMilliseconds); var count = client.GetMessageCount(); if (count == 0) { return; } Functions.Log.Debug("We've got new {0} messages in '{1}'", count, info.User); //Send messages to sorting block for (var i = 0; i < count; i++) { try { var mailInfo = new MessageInfo { IsSpam = false, Mail = client.GetMessage(i + 1), Type = MessageType.UNKNOWN, Subtype = null, Recipient = null, Mailbox = info }; Functions.Log.Debug("Download message from '{0}'. Size: {1}b", info.User, mailInfo.Mail.RawMessage.Length); while (!_sortMailDataBlock.Post(mailInfo)) { Thread.Sleep(500); } //Save every mail to archive Functions.Log.Debug("Archive message"); Functions.Archive.Info(Functions.MessageToString(mailInfo.Mail)); } catch (Exception ex) { Functions.Log.Error("Parse email error: {0}", ex.Message); Functions.ErrorsCounters[info.Type].Increment(); //Archive mail anyway Functions.Log.Debug("Archive message"); Functions.Archive.Info(Encoding.Default.GetString(client.GetMessageAsBytes(i + 1))); } if (_config.DeleteMail) { client.DeleteMessage(i + 1); } if (_stopPipeline) { break; } } Functions.Log.Debug("Done with '{0}'", info.User); } } catch (Exception ex) { Functions.Log.Error("General error - type: {0}, message: {1}", ex, ex.Message); Functions.ErrorsCounters[info.Type].Increment(); } }