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)
 {
     try
     {
         e.Stream.Close();
     }
     catch (Exception error)
     {
         _log.Error("error while closing message stream", error);
     }
 }
示例#3
0
 private void OnSessionMessageStoringCancelled(object sender, SMTP_e_MessageStored e)
 {
     CloseStream(e.Stream);
 }