private void OnNewMessage(object sender, EventArgs e) { if (e is NewPop3MessageEventArgs && sender is EMailRouterPop3BoxMessageLoader) { EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal(); if (internalPop3Box != null && !internalPop3Box.Activity.IsActive) { internalPop3Box = null; } UserLight prevUser = Security.CurrentUser; Alerts2.SendToCurrentUser = true; try { using (DbTransaction tran = DbTransaction.Begin()) { EMailRouterPop3BoxMessageLoader loader = (EMailRouterPop3BoxMessageLoader)sender; Pop3Message msg = ((NewPop3MessageEventArgs)e).Message; string TicketUID = TicketUidUtil.LoadFromString(msg.Subject == null ? string.Empty : msg.Subject); EMailMessageAntiSpamRuleRusult result = EMailMessageAntiSpamRuleRusult.Deny; if (loader.Owner.IsInternal) { int UserId = DBUser.GetUserByEmail(EMailMessage.GetSenderEmail(msg), false); if (TicketUID != string.Empty && UserId > 0) { result = EMailMessageAntiSpamRuleRusult.Accept; } } else { if (PortalConfig.UseAntiSpamFilter) { result = EMailMessageAntiSpamRule.Check(loader.Owner, msg); } else { result = EMailMessageAntiSpamRuleRusult.Accept; } } int EMailMessageId = -1; // OZ: [2007-01-29] EMailMessageLog if (EmailLogSettings != null) { string from = string.Empty; if (msg.Headers["Reply-To"] != null) { from = msg.Headers["Reply-To"]; } //else if (msg.Headers["Sender"] != null) //{ // from = msg.Headers["Sender"]; //} else if (msg.Headers["From"] != null) { from = msg.Headers["From"]; } EMailMessageLog.Add(from, msg.Headers["To"] != null ? msg.Headers["To"] : string.Empty, msg.Headers["Subject"] != null ? msg.Headers["Subject"] : string.Empty, loader.Owner.EMailRouterPop3BoxId, result); } // switch (result) { case EMailMessageAntiSpamRuleRusult.Pending: // Register Email Message EMailMessageId = RegisterEmail(loader.Owner.EMailRouterPop3BoxId, msg); // Add to pending email table EMailMessage.MarkAsPendingMessage(EMailMessageId); break; case EMailMessageAntiSpamRuleRusult.Accept: // Register Email Message EMailMessageId = RegisterEmail(loader.Owner.EMailRouterPop3BoxId, msg); if (TicketUID == string.Empty) { int IncidentId = EMailMessage.CreateNewIncident(EMailMessageId, loader.Owner, msg); } else { // Assign By Ticket int IncidentId = FindIncidentByTicket(TicketUID); if (IncidentId != -1) { int creatorId, issueBoxId; using (IDataReader reader = DBIncident.GetIncident(IncidentId, 0, 1)) { reader.Read(); creatorId = (int)reader["CreatorId"]; issueBoxId = (int)reader["IncidentBoxId"]; } int stateId, managerId, responsibleId; bool isResposibleGroup; ArrayList users = new ArrayList(); Issue2.GetIssueBoxSettings(issueBoxId, out stateId, out managerId, out responsibleId, out isResposibleGroup, users); EMailMessage.LogOnCreator(creatorId, msg); int ThreadNodeId = EMailMessage.AddToIncidentMessage(loader.Owner.IsInternal, IncidentId, EMailMessageId, msg); if (EMailMessage.ProcessXIbnHeaders(IncidentId, ThreadNodeId, msg)) { try { ArrayList excludeUsers = EMailRouterOutputMessage.Send(IncidentId, loader.Owner, msg); SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, IncidentId, -1, excludeUsers); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); Log.WriteError(ex.ToString()); } } } else { // Add to pending email table if (!loader.Owner.IsInternal) { EMailMessage.MarkAsPendingMessage(EMailMessageId); } } } break; case EMailMessageAntiSpamRuleRusult.Deny: // Do nothing break; } tran.Commit(); } } finally { Alerts2.SendToCurrentUser = false; if (Security.CurrentUser != prevUser) { Security.SetCurrentUser(prevUser); } } } }