private MailSoap12TransportBinding CreateMailMessage(Message message) { // Attach a To header, so that the SMTP/MIME SOAP 1.2 protocol can be complied with message.Headers.To = this.RemoteAddress.Uri; MailSoap12TransportBinding mail = new MailSoap12TransportBinding(message); if (_mailHandler.OutboxServerConfiguration.ReplyAddress == null || _mailHandler.OutboxServerConfiguration.ReplyAddress == "") { throw new dk.gov.oiosi.communication.handlers.email.MailBindingFieldMissingException("replyAddress in the configuration file"); } else { mail.From = MailSoap12TransportBinding.TrimMailAddress(_mailHandler.OutboxServerConfiguration.ReplyAddress); } if (mail.To == null || mail.To == "") { mail.To = MailSoap12TransportBinding.TrimMailAddress(this.RemoteAddress.Uri); } return(mail); }
private MailSoap12TransportBinding CreateMailMessage(Message message) { MailSoap12TransportBinding mail = new MailSoap12TransportBinding(message); // 2. Check mail headers of incoming request if (_requestMessage.ReplyTo != null && _requestMessage.ReplyTo != "") { mail.To = _requestMessage.ReplyTo; } else if (_requestMessage.From != null && _requestMessage.From != "") { mail.To = _requestMessage.From; } else { throw new RaspEmailReplyCouldNotBeSentException(new dk.gov.oiosi.communication.handlers.email.MailBindingFieldMissingException("From")); } // Try to set the FROM header of the mail if (mail.From == null || mail.From == "") { mail.From = MailSoap12TransportBinding.TrimMailAddress(this.pMailHandler.InboxServerConfiguration.ReplyAddress); } //TODO: remove this hack, only for testing message.Headers.To = new Uri("mailto:" + _requestMessage.From); WCFLogger.Write(System.Diagnostics.TraceEventType.Verbose, "RequestContext created the reply mail"); return(mail); }
private MailSoap12TransportBinding CreateMailMessage(Message message) { // Attach a To header, so that the SMTP/MIME SOAP 1.2 protocol can be complied with message.Headers.To = this.RemoteAddress.Uri; MailSoap12TransportBinding mail = null; string replyAddress = _mailHandler.OutboxServerConfiguration.ReplyAddress; if (string.IsNullOrEmpty(replyAddress)) { throw new MailBindingFieldMissingException("replyAddress in the configuration file"); } else { string fromAddress = MailSoap12TransportBinding.TrimMailAddress(_mailHandler.OutboxServerConfiguration.ReplyAddress); mail = new MailSoap12TransportBinding(message, fromAddress); mail.From = fromAddress; } if (mail.To == null || mail.To == "") { mail.To = MailSoap12TransportBinding.TrimMailAddress(this.RemoteAddress.Uri); } return(mail); }
/// <summary> /// Constructor /// </summary> /// <param name="channelManager">channel handler</param> /// <param name="mailQueue">mail queue</param> public RaspEmailReplyChannel(ChannelManagerBase channelManager, IMailHandler mailHandler, MailSoap12TransportBinding msg, RaspEmailBindingElement bindingElement) : base(channelManager) { _msg = msg; _mailHandler = mailHandler; _asyncTryReceiveRequest = new AsyncTryReceiveRequest(TryReceiveRequest); _bindingElement = bindingElement; }
/// <summary> /// The request /// </summary> /// <param name="message">The request System.ServiceModel.Channels.Message to be transmitted</param> /// <param name="timeout">The System.TimeSpan that specifies the interval of time within which a response /// must be received</param> /// <returns></returns> public Message Request(Message message, TimeSpan timeout) { WCFLogger.Write(TraceEventType.Start, "Mail request channel starting request"); Message reply = null; ThrowIfDisposedOrNotOpen(); // Send System.Diagnostics.Debug.Write("Mail requestChannel send request."); string id = _mailHandler.Send(CreateMailMessage(message)); // If the message sent was a fault, don't expect a reply if (message.IsFault) { message.Close(); WCFLogger.Write(TraceEventType.Stop, "Mail request channel finishing sending a fault"); return(null); } try { // Wait for the reply AutoResetEvent onAbort = new AutoResetEvent(false); _threadsDequeueing.Add(onAbort); MailSoap12TransportBinding mail = _mailHandler.Dequeue(id, timeout, onAbort); // If dequeue returned null, someone stopped it, throw aborted exception if (mail == null) { return(null); } // Get the WCF Message reply = mail.Attachment.WcfMessage; WCFLogger.Write(TraceEventType.Verbose, "Mail request channel got a reply"); } catch (CommunicationObjectAbortedException) { message.Close(); throw; } catch (TimeoutException) { message.Close(); throw; } catch (Exception e) { this.Fault(); message.Close(); throw new EmailResponseNotGottenException(e); } WCFLogger.Write(TraceEventType.Stop, "Mail request channel finishing requesting"); return(reply); }
/// <summary> /// De-queue the first mail /// </summary> /// <returns></returns> public override MailSoap12TransportBinding Dequeue() { if (_firstMessage != null) { MailSoap12TransportBinding firstMessage = _firstMessage; _firstMessage = null; return(firstMessage); } else { return(null); } }
/// <summary> /// De-queues the first mail from the internal Inbox mail queue. Waits until timeout has ocurred. /// </summary> /// <param name="onAbortDequeueing">Set when the dequeueing is supposed to stop before the timeout occurs</param> /// <param name="timeout">Time parameter</param> public override MailSoap12TransportBinding Dequeue(TimeSpan timeout, AutoResetEvent onAbortDequeueing) { if (_firstMessage != null) { MailSoap12TransportBinding firstMessage = _firstMessage; _firstMessage = null; return(firstMessage); } else { return(null); } }
/// <summary> /// OnAcceptChannel event /// </summary> /// <param name="timeout"></param> /// <returns></returns> protected override IReplyChannel OnAcceptChannel(TimeSpan timeout) { Thread.CurrentThread.Name = "RaspEmailChannelListener.OnAcceptChannel"; WCFLogger.Write(System.Diagnostics.TraceEventType.Start, "Listener starting to listen for a mail..."); MailSoap12TransportBinding mail = pMailHandler.Dequeue(timeout, _onEndDequeueing); if (mail == null) { WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "Listener got no mail."); WCFLogger.Write(System.Diagnostics.TraceEventType.Stop, "Listener finished listening for a mail."); return(null); } else { WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "Listener found a mail."); WCFLogger.Write(System.Diagnostics.TraceEventType.Stop, "Listener finished listening for a mail."); return(new EmailReplyChannel(this, pMailHandler, mail, pContext.Binding.Elements.Find <EmailBindingElement>())); } }
/// <summary> /// Returns a value that indicates whether a request is received before a specified /// interval of time elapses /// </summary> /// <param name="timeout">The System.TimeSpan that specifies how long the receive of a request operation /// has to complete before timing out and returning false</param> /// <param name="context">The System.ServiceModel.Channels.RequestContext received</param> /// <returns>true if a request message is received before the specified interval of time /// elapses; otherwise false</returns> public bool TryReceiveRequest(TimeSpan timeout, out RequestContext context) { context = null; try { if (_msg != null) { context = new EmailRequestContext(_msg, _mailHandler, _bindingElement); _msg = null; return(true); } WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "Received an incoming mail"); } catch (TimeoutException) { return(false); } return(true); }
/// <summary> /// Returns a value that indicates whether a request is received before a specified /// interval of time elapses /// </summary> /// <param name="timeout">The System.TimeSpan that specifies how long the receive of a request operation /// has to complete before timing out and returning false</param> /// <param name="context">The System.ServiceModel.Channels.RequestContext received</param> /// <returns>true if a request message is received before the specified interval of time /// elapses; otherwise false</returns> public bool TryReceiveRequest(TimeSpan timeout, out RequestContext context) { context = null; try { if (_msg != null) { context = new RaspEmailRequestContext(_msg, _mailHandler, _bindingElement); _msg = null; return(true); } WCFLogger.Write(System.Diagnostics.TraceEventType.Information, "Received an incoming mail"); } catch (TimeoutException) { return(false); } // TODO: Used to be true, but now we want one message per channel //return true; return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="msg">The incoming System.ServiceModel.Channels.Message that contains the request</param> /// <param name="mailHandler">mailhandler</param> public RaspEmailRequestContext(MailSoap12TransportBinding msg, IMailHandler mailHandler, RaspEmailBindingElement bindingElement) { _requestMessage = msg; pMailHandler = mailHandler; _bindingElement = bindingElement; }
/// <summary> /// Constructor /// </summary> /// <param name="firstMessage">The first message in the queue</param> /// <param name="mailHandler">The mail handler from which the rest of the messages will be gotten</param> public RaspEmailQueue(MailSoap12TransportBinding firstMessage, RaspMailHandler mailHandler) : base(mailHandler) { _firstMessage = firstMessage; _mailHandler = mailHandler; }