Beispiel #1
0
        /// <summary>
        /// Approves the pending.
        /// </summary>
        /// <param name="EMailMessageId">The E mail message id.</param>
        public static void ApprovePending(int EMailMessageId)
        {
            // Stop Double Approve
            if (!PendingEMailMessageRow.Contains(EMailMessageId))
            {
                return;
            }

            using (DbTransaction tran = DbTransaction.Begin())
            {
                // Remove from pending
                PendingEMailMessageRow.DeleteByEMailMessageId(EMailMessageId);

                // Load Pop3 Message
                EMailMessageInfo   msgInfo  = EMailMessageInfo.Load(EMailMessageId);
                EMailRouterPop3Box emailBox = EMailRouterPop3Box.Load(msgInfo.EMailRouterPop3BoxId);

                Pop3Message msg = EMailMessage.GetPop3Message(EMailMessageId);

                // Add User to White Lits
                string SenderEmail = EMailMessage.GetSenderEmail(msg);
                //if(!WhiteListItem.Contains(SenderEmail))

                if (PortalConfig.UseAntiSpamFilter && PortalConfig.AutoFillWhiteList)
                {
                    WhiteListItem.Create(SenderEmail);
                }

                string TicketUID = TicketUidUtil.LoadFromString(msg.Subject == null ? string.Empty : msg.Subject);

                if (TicketUID == string.Empty)
                {
                    int IncidentId = CreateNewIncident(EMailMessageId, emailBox, msg);

                    // Automaticaly by Incident.CreateFromEmail
                    //EMailRouterOutputMessage.Send(IncidentId, emailBox, msg);
                }
                else
                {
                    // Assign By Ticket
                    int IncidentId = FindIncidentByTicket(TicketUID);

                    if (IncidentId != -1)
                    {
                        int creatorId, issueBoxId;
                        using (IDataReader reader = Incident.GetIncident(IncidentId))
                        {
                            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);

                        UserLight prevUser = LogOnCreator(creatorId, msg);

                        int ThreadNodeId = AddToIncidentMessage(emailBox.IsInternal, IncidentId, EMailMessageId, msg);

                        if (ProcessXIbnHeaders(IncidentId, ThreadNodeId, msg))
                        {
                            ArrayList excludeUsers = EMailRouterOutputMessage.Send(IncidentId, emailBox, msg);

                            // O.R. [2008-09-09]: Exclude inactive users
                            if (responsibleId > 0 && User.GetUserActivity(responsibleId) != User.UserActivity.Active)
                            {
                                responsibleId = -1;
                            }
                            ArrayList activeUsers = new ArrayList();
                            foreach (int userId in users)
                            {
                                if (User.GetUserActivity(userId) == User.UserActivity.Active)
                                {
                                    activeUsers.Add(userId);
                                }
                            }
                            //

                            Issue2.SendAlertsForNewIssue(IncidentId, managerId, responsibleId, activeUsers, excludeUsers);
                        }
                    }
                    else
                    {
                        IncidentId = CreateNewIncident(EMailMessageId, emailBox, msg);

                        // Automaticaly by Incident.CreateFromEmail
                        //EMailRouterOutputMessage.Send(IncidentId, emailBox, msg);
                    }
                }
                tran.Commit();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Copies to incident.
        /// </summary>
        /// <param name="emailMessageId">The email message id.</param>
        /// <param name="incidentId">The incident id.</param>
        public static void CopyToIncident(int emailMessageId, int incidentId)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                // Remove from pending
                PendingEMailMessageRow.DeleteByEMailMessageId(emailMessageId);

                // Load Pop3 Message
                EMailMessageInfo   msgInfo  = EMailMessageInfo.Load(emailMessageId);
                EMailRouterPop3Box emailBox = EMailRouterPop3Box.Load(msgInfo.EMailRouterPop3BoxId);

                Pop3Message msg = EMailMessage.GetPop3Message(emailMessageId);

                // Add User to White Lits
                string SenderEmail = EMailMessage.GetSenderEmail(msg);
                //if(!WhiteListItem.Contains(SenderEmail))

                if (PortalConfig.UseAntiSpamFilter && PortalConfig.AutoFillWhiteList)
                {
                    WhiteListItem.Create(SenderEmail);
                }


                int creatorId, issueBoxId;
                using (IDataReader reader = Incident.GetIncident(incidentId))
                {
                    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);

                UserLight prevUser = LogOnCreator(creatorId, msg);

                int ThreadNodeId = AddToIncidentMessage(emailBox.IsInternal, incidentId, emailMessageId, msg);

                if (ProcessXIbnHeaders(incidentId, ThreadNodeId, msg))
                {
                    ArrayList excludeUsers = EMailRouterOutputMessage.Send(incidentId, emailBox, msg);

                    // O.R. [2008-09-09]: Exclude inactive users
                    if (responsibleId > 0 && User.GetUserActivity(responsibleId) != User.UserActivity.Active)
                    {
                        responsibleId = -1;
                    }
                    ArrayList activeUsers = new ArrayList();
                    foreach (int userId in users)
                    {
                        if (User.GetUserActivity(userId) == User.UserActivity.Active)
                        {
                            activeUsers.Add(userId);
                        }
                    }
                    //

                    Issue2.SendAlertsForNewIssue(incidentId, managerId, responsibleId, activeUsers, excludeUsers);
                }

                tran.Commit();
            }
        }
        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);
                    }
                }
            }
        }