public void TestBuildContextEncapsulationRoundTrip(string file) { var directMessage = MimeMessage.Load(file); var context = directMessage.DirectContext(); // // Metadata // Assert.Equal("1.0", context.Metadata.Version); Assert.Equal("<*****@*****.**>", context.Metadata.Id); Assert.Equal("hl7v2", context.Metadata.Encapsulation.Type); var encapsulations = Enumerable.ToList(directMessage.SelectEncapulations()); Assert.Equal(1, encapsulations.Count()); Assert.Equal(@"MSH |^ ~\&| SENDING_APPLICATION | SENDING_FACILITY | RECEIVING_APPLICATION | RECEIVING_FACILITY | 20110613083617 || ADT ^ A01 | 934576120110613083617 | P | 2.3 |||| EVN | A01 | 20110613083617 ||| PID | 1 || 135769 || MOUSE ^ MICKEY ^|| 19281118 | M ||| 123 Main St.^^ Lake Buena Vista ^ FL ^ 32830 || (407)939 - 1289 ^^^ [email protected] ||||| 1719 | 99999999 |||||||||||||||||||| PV1 | 1 | O |||||^^^^^^^^|^^^^^^^^", encapsulations.Single().DecodeBody()); var echoMessage = EchoContext.Process(directMessage); var messageRebuilt = echoMessage.DirectContext(); AssertEqual(context, messageRebuilt); AssertEqual(Enumerable.ToList(directMessage.SelectEncapulations()), Enumerable.ToList(echoMessage.SelectEncapulations())); }
public bool Receive(ISmtpMessage data) { var message = data.GetEnvelope().Message; if (message.IsDSN()) { Log.For <LoopBackContext>().Debug("Ignore DSN"); return(true); } if (message.IsMDN()) { Log.For <LoopBackContext>().Debug("Ignore MDN"); return(true); } var directMessage = MimeMessage.Load(message.ToString().ToStream()); try { if (!directMessage.ContainsDirectContext()) { Log.For <LoopBackContext>() .Warn($"Message does not contain context. MessageId={directMessage.MessageId}"); var dsnMessage = ReturnNoContextMessage(directMessage, @"No Context found"); DropMessage(dsnMessage); return(true); } var pongMessage = EchoContext.Process(directMessage); DropMessage(pongMessage); Log.For <LoopBackContext>() .Info($"Message context pong response. MessageId={pongMessage.MessageId} RelatesToMessageId={message.ID}"); } catch (Exception ex) { Log.For <LoopBackContext>() .Error($"Message exception. MessageId={message.ID} :: Exception: {ex}"); var dsnMessage = ReturnNoContextMessage(directMessage, ex.Message); DropMessage(dsnMessage); } return(true); }
public void TestBuildContextRoundTrip(string file) { var directMessage = MimeMessage.Load(file); var context = directMessage.DirectContext(); var message = EchoContext.Process(directMessage); var directMessageRebuilt = MimeMessage.Load(message.ToString().ToStream()); var contextRebuilt = directMessageRebuilt.DirectContext(); AssertEqual(context, contextRebuilt); Assert.StartsWith("<", contextRebuilt.Headers[ContextStandard.ContentIdHeader]); Assert.EndsWith(">", contextRebuilt.Headers[ContextStandard.ContentIdHeader]); Assert.StartsWith("<", directMessageRebuilt.Headers[MailStandard.Headers.DirectContext]); Assert.EndsWith(">", directMessageRebuilt.Headers[MailStandard.Headers.DirectContext]); }