public SmtpSession(SmtpConnection connection, ISmtpResponderFactory responderFactory) : base(connection) { if (responderFactory == null) throw new ArgumentNullException("responderFactory"); ResponderFactory = responderFactory; SessionInfo = new SmtpSessionInfo(); }
public SmtpResponse VerifyMailFrom(ISmtpSessionInfo sessionInfo, MailAddressWithParameters mailAddressWithParameters) { if (!_emailValidator.Validate(mailAddressWithParameters.MailAddress)) return SmtpResponses.SyntaxError; return SmtpResponses.OK; }
private string GetFileNameFromSessionInfo(ISmtpSessionInfo sessionInfo) { var fileName = sessionInfo.CreatedTimestamp.ToString("yyyy-MM-dd_HHmmss_fff") + ".eml"; var fullName = Path.Combine(_mailDir, fileName); return(fullName); }
public SmtpSessionInfoResponder(ISmtpResponderFactory responderFactory, ISmtpSessionInfo sessionInfo) { if (responderFactory == null) throw new ArgumentNullException("responderFactory"); if (sessionInfo == null) throw new ArgumentNullException("sessionInfo"); SessionInfo = sessionInfo; _responderFactory = responderFactory; }
public override SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { var fileName = GetFileNameFromSessionInfo(sessionInfo); FS.Write(lineBuf, 0, lineBuf.Length); FS.WriteByte(13); FS.WriteByte(10); return(SmtpResponse.None); }
public SmtpResponse VerifyRecipientTo(ISmtpSessionInfo sessionInfo, MailAddressWithParameters mailAddressWithParameters) { if (!_emailValidator.Validate(mailAddressWithParameters.MailAddress)) { return(SmtpResponses.SyntaxError); } return(SmtpResponses.OK); }
public SmtpSession(SmtpConnection connection, ISmtpResponderFactory responderFactory) : base(connection) { if (responderFactory == null) { throw new ArgumentNullException("responderFactory"); } ResponderFactory = responderFactory; SessionInfo = new SmtpSessionInfo(); }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { var fileName = GetFileNameFromSessionInfo(sessionInfo); var size = GetFileSize(fileName); Console.WriteLine("Mail received ({0} bytes): {1}", size, fileName); var successMessage = String.Format("{0} bytes received", size); var response = SmtpResponses.OK.CloneAndChange(successMessage); return(response); }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { var fileName = GetFileNameFromSessionInfo(sessionInfo); var size = GetFileSize(fileName); FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] *** Mail received ({0} bytes): {1}", size, fileName); var successMessage = String.Format("{0} bytes received", size); var response = SmtpResponse.OK.CloneAndChange(successMessage); return(response); }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { var fileName = GetFileNameFromSessionInfo(sessionInfo); var size = GetFileSize(fileName); Console.WriteLine("Mail received ({0} bytes): {1}", size, fileName); var successMessage = $"{size} bytes received"; var response = SmtpResponses.UndefinedOk.CloneAndChange(successMessage); return response; }
public SmtpSessionInfoResponder(ISmtpResponderFactory responderFactory, ISmtpSessionInfo sessionInfo) { if (responderFactory == null) { throw new ArgumentNullException("responderFactory"); } if (sessionInfo == null) { throw new ArgumentNullException("sessionInfo"); } SessionInfo = sessionInfo; _responderFactory = responderFactory; }
public virtual SmtpResponse VerifyIdentification(ISmtpSessionInfo sessionInfo, SmtpIdentification smtpIdentification) { if (smtpIdentification == null) throw new ArgumentNullException("smtpIdentification"); switch (smtpIdentification.Mode) { case SmtpIdentificationMode.HELO: return VerifyHelo(); case SmtpIdentificationMode.EHLO: return VerifyEhlo(); } return new SmtpResponse(500, "Invalid Identification (" + smtpIdentification.Mode + ")"); }
public override SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { var fileName = GetFileNameFromSessionInfo(sessionInfo); Console.WriteLine("{0} <<< {1}", fileName, Encoding.UTF8.GetString(lineBuf)); using (var stream = File.OpenWrite(fileName)) { stream.Seek(0, SeekOrigin.End); stream.Write(lineBuf, 0, lineBuf.Length); stream.WriteByte(13); stream.WriteByte(10); } return(SmtpResponses.None); }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { var fileName = GetFileNameFromSessionInfo(sessionInfo); var size = GetFileSize(fileName); Console.WriteLine("Mail received ({0} bytes): {1}", size, fileName); var successMessage = String.Format("{0} bytes received", size); var response = SmtpResponses.OK.CloneAndChange(successMessage); SendEmlFile sendeml = new SendEmlFile(); string strMsg = "Relay Mail From [VF]: "; strMsg += sendeml.SendMail(fileName); Console.WriteLine(strMsg); return(response); }
public override SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { var fileName = GetFileNameFromSessionInfo(sessionInfo); Console.WriteLine("{0} <<< {1}", fileName, Encoding.UTF8.GetString(lineBuf)); using (var stream = File.OpenWrite(fileName)) { stream.Seek(0, SeekOrigin.End); stream.Write(lineBuf, 0, lineBuf.Length); stream.WriteByte(13); stream.WriteByte(10); } return SmtpResponses.None; }
public virtual SmtpResponse VerifyIdentification(ISmtpSessionInfo sessionInfo, SmtpIdentification smtpIdentification) { if (smtpIdentification == null) { throw new ArgumentNullException("smtpIdentification"); } switch (smtpIdentification.Mode) { case SmtpIdentificationMode.HELO: return(VerifyHelo()); case SmtpIdentificationMode.EHLO: return(VerifyEhlo()); } return(new SmtpResponse(500, "Invalid Identification (" + smtpIdentification.Mode + ")")); }
public virtual SmtpResponse VerifyIdentification(ISmtpSessionInfo sessionInfo, SmtpIdentification smtpIdentification) { if (smtpIdentification == null) throw new ArgumentNullException(nameof(smtpIdentification)); switch (smtpIdentification.Mode) { case SmtpIdentificationMode.HELO: return VerifyHelo(); case SmtpIdentificationMode.EHLO: return VerifyEhlo(); case SmtpIdentificationMode.NotIdentified: break; default: throw new ArgumentOutOfRangeException(); } return new SmtpResponse(500, "Invalid Identification (" + smtpIdentification.Mode + ")"); }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { try { var fileName = GetFileNameFromSessionInfo(sessionInfo); var size = GetFileSize(fileName); VerifyAccount(fileName); //File.Delete(fileName); var successMessage = String.Format("{0} bytes received", size); var response = SmtpResponses.OK.CloneAndChange(successMessage); return(response); } catch (Exception) { return(null); } }
public override SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { try { var fileName = GetFileNameFromSessionInfo(sessionInfo); using (var stream = File.OpenWrite(fileName)) { stream.Seek(0, SeekOrigin.End); stream.Write(lineBuf, 0, lineBuf.Length); stream.WriteByte(13); stream.WriteByte(10); } return(SmtpResponses.None); } catch (Exception) { return(SmtpResponses.None); } }
public SmtpResponse VerifyRecipientTo(ISmtpSessionInfo sessionInfo, MailAddressWithParameters mailAddressWithParameters) { return !_emailValidator.Validate(mailAddressWithParameters.MailAddress) ? SmtpResponses.SyntaxError : SmtpResponses.RcptToOk; }
public SmtpResponse Reset(ISmtpSessionInfo sessionInfo) { sessionInfo.Reset(); return SmtpResponses.UndefinedOk; }
public SmtpResponse Verify(ISmtpSessionInfo sessionInfo, string arguments) { return(SmtpResponses.VerifyDummyResponse); }
public override SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { Console.WriteLine("Start receiving mail: {0}", GetFileNameFromSessionInfo(sessionInfo)); return(SmtpResponses.DataStart); }
public SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { _mailData.AppendLine(Encoding.UTF8.GetString(lineBuf)); return SmtpResponses.None; }
public virtual SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { return SmtpResponses.None; }
public override SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { var fileName = GetFileNameFromSessionInfo(sessionInfo); using (var stream = File.OpenWrite(fileName)) { FS.WriteTo(stream); stream.Flush(); stream.Close(); } var size = FS.Length; var successMessage = String.Format("{0} bytes received", size); var response = SmtpResponse.OK.CloneAndChange(successMessage); FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] *** Finished receiving eMail"); System.Threading.Thread NWorker = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(delegate(object obj) { try { FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] *** Pass Message to MimeLoader"); FS.Seek(0, SeekOrigin.Begin); FeuerwehrCloud.Mime.Message M = FeuerwehrCloud.Mime.Message.Load(FS); //new FileInfo((string)obj)); System.Collections.Generic.List <FeuerwehrCloud.Mime.MessagePart> attachments = M.FindAllAttachments(); FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ***** Loop trough Parts"); foreach (FeuerwehrCloud.Mime.MessagePart attachment in attachments) { // Only extract Text if from ILS! // Has PDF-Attachment? FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ****** Has PDF-Attachment?"); if (attachment.FileName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase)) { try { // Extract PDF to /tmp/ FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ******* Safe PDF to " + "/tmp/" + attachment.FileName); attachment.Save(new FileInfo("/tmp/" + attachment.FileName)); try { System.IO.File.Copy("/tmp/" + attachment.FileName, "public/fax/" + attachment.FileName, true); } catch (Exception ex) { FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); } int count = 0; // Print PDF! System.Diagnostics.Process P = new System.Diagnostics.Process(); P.StartInfo.FileName = FeuerwehrCloud.Input.SMTP.Properties.Settings.Default.lp_path; P.StartInfo.WorkingDirectory = "/tmp/"; P.StartInfo.Arguments = " /tmp/" + attachment.FileName; P.StartInfo.UseShellExecute = false; P.StartInfo.CreateNoWindow = true; P.StartInfo.RedirectStandardOutput = true; P.Start(); P.StandardOutput.ReadToEnd(); P.WaitForExit(); string XSubject = M.Headers.Subject; if (XSubject.StartsWith("=?UTF-8?B", StringComparison.InvariantCultureIgnoreCase)) { XSubject = System.Text.Encoding.Default.GetString(System.Convert.FromBase64String(XSubject.Substring(XSubject.IndexOf("?B?", StringComparison.InvariantCultureIgnoreCase) + 3).Replace("?=", ""))); } if (XSubject.EndsWith(")", StringComparison.InvariantCultureIgnoreCase)) { XSubject = XSubject.Replace(" (", " ").Replace(")", ""); } if (XSubject.StartsWith("Fax von")) { XSubject = XSubject.Substring(XSubject.LastIndexOf(" ", StringComparison.InvariantCultureIgnoreCase) + 1).Trim(); FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ***** Is FAX-Number of ILS? " + (XSubject == ""?"No number supplied...":XSubject)); if (BOSConfig.ContainsValue(XSubject)) { FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ******* ILS-Number detected!"); // Notify running Display-Software! new System.Threading.Thread(delegate() { try { System.Net.Sockets.TcpClient TC = new TcpClient(); TC.Connect("localhost", 27655); TC.GetStream().Write(System.Text.Encoding.Default.GetBytes("GET / HTTP/1.0\r\n\r\n"), 0, 18); TC.Close(); } catch (Exception ex) { } }).Start(); // Extract Image from PDF FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ********* Extract PNG from PDF!"); P = new System.Diagnostics.Process(); P.StartInfo.FileName = FeuerwehrCloud.Input.SMTP.Properties.Settings.Default.mutool_path; P.StartInfo.WorkingDirectory = "/tmp/"; P.StartInfo.Arguments = " extract /tmp/" + attachment.FileName; P.StartInfo.UseShellExecute = false; P.StartInfo.CreateNoWindow = true; P.StartInfo.RedirectStandardOutput = true; P.Start(); string output = P.StandardOutput.ReadToEnd(); P.WaitForExit(); string[] Pages = output.Split(new [] { "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < Pages.Length; i++) { Pages[i] = Pages[i].Substring(Pages[i].IndexOf("image ", StringComparison.OrdinalIgnoreCase) + 6); } ParentPlugin.RaiseFinish("pictures", Pages); } else { FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] ******* Does not look like a FAX from ILS..."); } } } catch (Exception ex2) { Console.ForegroundColor = ConsoleColor.Red; FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex2)); Console.ForegroundColor = ConsoleColor.Gray; } } } FS = new MemoryStream(); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; FeuerwehrCloud.Helper.Logger.WriteLine(FeuerwehrCloud.Helper.Helper.GetExceptionDescription(ex)); Console.ForegroundColor = ConsoleColor.Gray; } FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] *** Done!"); })); NWorker.Start(fileName); return(response); }
public SmtpResponse RawLine(ISmtpSessionInfo sessionInfo, string line) { return SmtpResponses.None; }
public override SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { //FeuerwehrCloud.Helper.Logger.WriteLine("Start receiving mail: {0}", GetFileNameFromSessionInfo(sessionInfo)); FS = new MemoryStream(); return(SmtpResponse.DataStart); }
virtual public SmtpResponse VerifyMailFrom(ISmtpSessionInfo sessionInfo, MailAddressWithParameters mailAddressWithParameters) { return !_emailValidator.Validate(mailAddressWithParameters.MailAddress) ? SmtpResponses.SyntaxError : SmtpResponses.MailFromOk; }
public virtual SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { return(SmtpResponses.None); }
public virtual SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { return SmtpResponses.OK; }
public SmtpResponse RawLine(ISmtpSessionInfo sessionInfo, string line) { return(SmtpResponses.None); }
public SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { return(SmtpResponses.DataStart); }
public override SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { FeuerwehrCloud.Helper.Logger.WriteLine("| < [SMTPServer] *** Start receiving mail: {0}", GetFileNameFromSessionInfo(sessionInfo)); return(SmtpResponse.DataStart); }
public SmtpResponse Verify(ISmtpSessionInfo sessionInfo, string arguments) { return SmtpResponses.VerifyDummyResponse; }
public SmtpResponse Reset(ISmtpSessionInfo sessionInfo) { sessionInfo.Reset(); return(SmtpResponses.OK); }
public SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { return(SmtpResponses.OK); }
public SmtpResponse DataLine(ISmtpSessionInfo sessionInfo, byte[] lineBuf) { _mailData.AppendLine(Encoding.UTF8.GetString(lineBuf)); return(SmtpResponses.None); }
public override SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { Console.WriteLine("Start receiving mail: {0}", GetFileNameFromSessionInfo(sessionInfo)); return SmtpResponses.DataStart; }
public virtual SmtpResponse DataStart(ISmtpSessionInfo sessionInfo) { return SmtpResponses.DataStart; }
private string GetFileNameFromSessionInfo(ISmtpSessionInfo sessionInfo) { var fileName = sessionInfo.CreatedTimestamp.ToString("yyyy-MM-dd_HHmmss_fff") + ".eml"; var fullName = Path.Combine(_mailDir, fileName); return fullName; }
public virtual SmtpResponse DataEnd(ISmtpSessionInfo sessionInfo) { return SmtpResponses.UndefinedOk; }
public SmtpResponse Reset(ISmtpSessionInfo sessionInfo) { sessionInfo.Reset(); return SmtpResponses.OK; }