Beispiel #1
0
        /// <summary>
        /// Raises <b>MessageStoringCompleted</b> event.
        /// </summary>
        /// <param name="reply">Default SMTP server reply.</param>
        /// <returns>Returns SMTP server reply what must be sent to the connected client.</returns>
        private SMTP_Reply OnMessageStoringCompleted(SMTP_Reply reply)
        {
            if (MessageStoringCompleted != null)
            {
                SMTP_e_MessageStored eArgs = new SMTP_e_MessageStored(this, m_pMessageStream, reply);
                MessageStoringCompleted(this, eArgs);

                return eArgs.Reply;
            }

            return reply;
        }
 private void OnSessionMessageStoringCancelled(object sender, SMTP_e_MessageStored e)
 {
     try
     {
         e.Stream.Close();
     }
     catch (Exception error)
     {
         _log.Error("error while closing message stream", error);
     }
 }
        private void OnSessionMessageStoringCompleted(object sender, SMTP_e_MessageStored e)
        {
            _log.Debug("begin processing message storing completed event");

            try
            {
                e.Stream.Flush();
                e.Stream.Seek(0, SeekOrigin.Begin);

                Mail_Message message = Mail_Message.ParseFromStream(e.Stream);
                message.Subject = Regex.Replace(message.Subject, @"\t", "");

                foreach (var requestInfo in e.Session.To
                                             .Where(x => e.Session.Tags.ContainsKey(x.Mailbox))
                                             .Select(x => (ApiRequest)e.Session.Tags[x.Mailbox]))
                {
                    try
                    {
                        _log.Debug("begin process request (" + requestInfo + ")");

                        CoreContext.TenantManager.SetCurrentTenant(requestInfo.Tenant);

                        if (requestInfo.Parameters != null)
                        {
                            foreach (var parameter in requestInfo.Parameters.Where(x => x.ValueResolver != null))
                            {
                                parameter.Value = parameter.ValueResolver.ResolveParameterValue(message);
                            }
                        }
                        if (requestInfo.FilesToPost != null)
                        {
                            requestInfo.FilesToPost = message.AllEntities.Where(IsAttachment).Select(GetAsAttachment).ToList();    
                        }
                        
                        if (requestInfo.FilesToPost == null || requestInfo.FilesToPost.Count > 0)
                        {
                            _apiService.EnqueueRequest(requestInfo);   
                        }

                        _log.Debug("end process request (" + requestInfo + ")");
                    }
                    catch (Exception ex)
                    {
                        _log.Error("error while processing request info", ex);
                    }
                }

            }
            catch (Exception error)
            {
                _log.Error("error while processing message storing completed event", error);
            }
            finally
            {
                e.Stream.Close();
            }

            _log.Debug("complete processing message storing completed event");
        }
 private void OnSessionMessageStoringCancelled(object sender, SMTP_e_MessageStored e)
 {
     CloseStream(e.Stream);
 }