Ejemplo n.º 1
0
        public static bool Contains(string from)
        {
            // All IBN User are included into white list (Automatically)
            #region Auto Users
            int emailUser = DBUser.GetUserByEmail(from, false);
            if (emailUser > 0)
            {
                return(true);
            }

            Client client = Common.GetClient(from);
            if (client != null)
            {
                return(true);
            }
            #endregion

            foreach (EMailMessageAntiSpamItemRow item in EMailMessageAntiSpamItemRow.List(from))
            {
                if (item.IsWhite)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static int UserLoginByExternalGate(int ObjectTypeId, int ObjectId, string GUID, string Email)
        {
            int    UserId = DBUser.GetUserByEmail(Email, true);
            string DBGUID = DBCommon.GetGateGuid(ObjectTypeId, ObjectId, UserId);

            if (0 != string.Compare(DBGUID, GUID, true))
            {
                // Audit
                if (PortalConfig.AuditWebLogin)
                {
                    HttpRequest request  = HttpContext.Current.Request;
                    string      referrer = "";
                    if (request.UrlReferrer != null)
                    {
                        referrer = String.Concat(request.UrlReferrer.Host, request.UrlReferrer.PathAndQuery);
                    }
                    string message = String.Format(CultureInfo.InvariantCulture,
                                                   "Failed IBN portal external login.\r\n\r\nEmail: {0}\r\nGate:{1}\r\nIP: {2}\r\nReferrer: {3}",
                                                   Email,
                                                   GUID,
                                                   request.UserHostAddress,
                                                   referrer);
                    Log.WriteEntry(message, System.Diagnostics.EventLogEntryType.FailureAudit);
                }
                //

                throw new AccessDeniedException();
            }

            return(UserId);
        }
Ejemplo n.º 3
0
        //		public static string[] GetExternalSendersByIncidentId(int IncidentId)
        //		{
        //			return EMailMessageRow.GetExternalSendersByIncidentId(IncidentId);
        //		}

        /// <summary>
        /// Logs the on creator.
        /// </summary>
        /// <param name="DefaultCreatorId">The default creator id.</param>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        internal static UserLight LogOnCreator(int DefaultCreatorId, Pop3Message msg)
        {
            if (Security.CurrentUser != null)
            {
                return(Security.CurrentUser);
            }

            int creatorId = DefaultCreatorId;

            int emailUser = DBUser.GetUserByEmail(EMailMessage.GetSenderEmail(msg), false);

            if (emailUser > 0)
            {
                // OZ: 2007-01-26: Fix problem: Mediachase.IBN.Business.AccessDeniedException: Access denied.
                //   at Mediachase.IBN.Business.Incident.CreateFromEmail
                using (IDataReader reader = DBUser.GetUserInfo(emailUser))
                {
                    if (reader.Read())
                    {
                        if (!(bool)reader["IsActive"])
                        {
                            emailUser = -1;
                        }
                    }
                    else
                    {
                        emailUser = -1;
                    }
                }
                //
            }

            if (emailUser > 0)
            {
                creatorId = emailUser;
            }

            UserLight creator = UserLight.Load(creatorId);

            return(Security.SetCurrentUser(creator));
        }
Ejemplo n.º 4
0
        protected virtual int GetUserIdByEmail(string from, bool onlyExternalSenders)
        {
            int userId = DBUser.GetUserByEmail(from, onlyExternalSenders);

            // Fix: If we've found inactive user. [8/18/2004]
            using (IDataReader reader = DBUser.GetUserInfo(userId))
            {
                if (reader.Read())
                {
                    if (!(bool)reader["IsActive"])
                    {
                        userId = -1;
                    }
                }
                else
                {
                    userId = -1;
                }
            }
            // End fix [8/18/2004]

            return(userId);
        }
Ejemplo n.º 5
0
        public static ArrayList Send(int IncidentId, EMailRouterPop3Box pop3Box, Pop3Message InMsg, string[] RecipientEmails)
        {
            ArrayList retVal = new ArrayList();

            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            EMailRouterIncidentBoxBlock settings = IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock;

            if (pop3Box.IsInternal)
            {
                #region Internal -> Extrenal
                // Internal -> Internal Info

                // 2009-06-16 OZ: Add Chech send emails to internal users
                if (settings.AllowEMailRouting)
                {
                    // 2007-02-12 OZ: "FN LN" <*****@*****.**>
                    string FromEmail = string.Format("\"{0} {1}\" <{2}>",
                                                     Security.CurrentUser.LastName,
                                                     Security.CurrentUser.FirstName,
                                                     pop3Box.EMailAddress);

                    OutputMessageCreator output2Iternal = new OutputMessageCreator(InMsg, IncidentId, pop3Box.EMailAddress, FromEmail);

                    // Exclude a message sender
                    //output2Iternal.AddIgnoreRecipient(EMailMessage.GetSenderEmail(InMsg));

                    // Load InternalUser
                    foreach (int UserId in GetInternalUsersByIncidentId(IncidentId))
                    {
                        output2Iternal.AddRecipient(UserId);
                        retVal.Add(UserId);
                    }

                    // Load InformationRecipientList
                    //				foreach(int infoRecipient in IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock.InformationRecipientList)
                    //				{
                    //					output2Iternal.AddRecipient(infoRecipient);
                    //				}

                    foreach (OutputMessage outputMsg in output2Iternal.Create())
                    {
                        //try
                        //{
                        SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, pop3Box.EMailRouterPop3BoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                        //}
                        //catch(Exception ex)
                        //{
                        //    System.Diagnostics.Trace.WriteLine(ex);
                        //    Log.WriteError(ex.ToString());
                        //}
                    }
                }

                // Internal -> Extrenal
                string publicEmail = FindEMailRouterPublicEmail(IncidentId);

                if (publicEmail != string.Empty)
                {
                    //EMailRouterPop3Box externalPop3Box = EMailRouterPop3Box.Load(realEMailBoxId);

                    OutputMessageCreator output2External = new OutputMessageCreator(InMsg, IncidentId, publicEmail, publicEmail);

                    // Load External Senders
//					foreach(string exRecipient in EMailMessage.GetExternalSendersByIncidentId(IncidentId))
//					{
//						output2External.AddRecipient(exRecipient);
//					}

                    // Load External Senders
                    foreach (EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(IncidentId))
                    {
                        output2External.AddRecipient(exRecipient.EMail);
                    }

                    // 2007-03-12 RecipientEmails Addon
                    if (RecipientEmails != null)
                    {
                        foreach (string exItem in RecipientEmails)
                        {
                            int emailUserId = DBUser.GetUserByEmail(exItem, false);
                            if (emailUserId > 0)
                            {
                                if (!retVal.Contains(emailUserId))
                                {
                                    output2External.AddRecipient(exItem);
                                    retVal.Add(emailUserId);
                                }
                            }
                            else
                            {
                                output2External.AddRecipient(exItem);
                            }
                        }
                    }
                    //

                    int emailBoxId = EMail.EMailRouterOutputMessage.FindEMailRouterPublicId(IncidentId);

                    foreach (OutputMessage outputMsg in output2External.Create())
                    {
                        //try
                        //{
                        SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, emailBoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                        //}
                        //catch(Exception ex)
                        //{
                        //    System.Diagnostics.Trace.WriteLine(ex);
                        //    Log.WriteError(ex.ToString());
                        //}
                    }
                }
                #endregion
            }
            else
            {
                if (!settings.AllowEMailRouting)
                {
                    return(retVal);
                }

                EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal();
                if (internalPop3Box == null)
                {
                    return(retVal);
                }

                #region                 // External -> Internal
                // External -> Internal

                string SenderName = EMailMessage.GetSenderName(InMsg);
                string FromEmail  = SenderName == string.Empty?internalPop3Box.EMailAddress:
                                    string.Format("\"{0}\" <{1}>",
                                                  SenderName,
                                                  internalPop3Box.EMailAddress);

                OutputMessageCreator output = new OutputMessageCreator(InMsg, IncidentId, internalPop3Box.EMailAddress, FromEmail);

                string Subject = (InMsg.Subject == null?string.Empty:InMsg.Subject);

                if (Subject == string.Empty)
                {
                    // OZ: Maybe:  Set Default Inicdent Title if subject is empty
                    //Subject = Incident.GetIncidentTitle(IncidentId);
                }

                if (TicketUidUtil.LoadFromString(Subject) == string.Empty)
                {
                    output.Subject = string.Format("[{0}] {1}", TicketUidUtil.Create(incidentBox.IdentifierMask, IncidentId), Subject);
                }

                foreach (int UserId in GetInternalUsersByIncidentId(IncidentId))
                {
                    output.AddRecipient(UserId);
                    retVal.Add(UserId);
                }

//				IncidentBoxDocument incidentDoc = IncidentBoxDocument.Load(incidentBox.IncidentBoxId);
//
//				foreach(int infoRecipient in incidentDoc.EMailRouterBlock.InformationRecipientList)
//				{
//					output.AddRecipient(infoRecipient);
//				}

                foreach (OutputMessage outputMsg in output.Create())
                {
                    //try
                    //{
                    SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, internalPop3Box.EMailRouterPop3BoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                    //}
                    //catch(Exception ex)
                    //{
                    //    System.Diagnostics.Trace.WriteLine(ex);
                    //    Log.WriteError(ex.ToString());
                    //}
                }
                #endregion
            }

            return(retVal);
        }
Ejemplo n.º 6
0
        public static void SendMessage(string[] To, string Subject, string Body, Mediachase.IBN.Business.ControlSystem.DirectoryInfo Attachments, string Mode, NameValueCollection Params)
        {
            // Cleanup Temporary files
            DbEMailTempFile.CleanUp();

            #region Validate Arguments
            if (To == null)
            {
                throw new ArgumentNullException("To");
            }

            if (Subject == null)
            {
                throw new ArgumentNullException("Subject");
            }

            if (Body == null)
            {
                throw new ArgumentNullException("Body");
            }

            //if (To.Length == 0)
            //    throw new ArgumentOutOfRangeException("To", "Email recipient list is empty.");

            if (Mode == null)
            {
                Mode = string.Empty;
            }

            if (Params == null)
            {
                Params = new NameValueCollection();
            }
            #endregion

            string FromEmail = string.Empty;

            switch (Mode)
            {
            case EMailClient.IssueMode:
            case EMailClient.SmtpTestMode:
                FromEmail = Alerts2.AlertSenderEmail;
                break;

            default:
                FromEmail = Security.CurrentUser.Email;
                break;
            }

            string FullFromEmail = string.Format("\"{0} {1}\" <{2}>",
                                                 Security.CurrentUser.LastName,
                                                 Security.CurrentUser.FirstName,
                                                 FromEmail);

            using (DbTransaction tran = DbTransaction.Begin())
            {
                EMailMessageLogSetting EmailLogSettings = EMailMessageLogSetting.Current;
                if (EmailLogSettings.IsActive)
                {
                    EMailMessageLog.CleanUp(EmailLogSettings.Period);
                }
                else
                {
                    EmailLogSettings = null;
                }

                Mode = Mode.ToLower();

                #region Pre-format incoming arguments
                switch (Mode)
                {
                case EMailClient.IssueMode:
                    if (Params["IssueId"] == null)
                    {
                        throw new ArgumentNullException("Params[\"IssueId\"]");
                    }

                    int IssueId = int.Parse(Params["IssueId"]);

                    // TODO: Validate Subject & Ticket
                    if (TicketUidUtil.LoadFromString(Subject) == string.Empty)
                    {
                        IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IssueId));

                        string IncidentTicket = Incident.GetIdentifier(IssueId);

                        if (incidentBox.Document.GeneralBlock.AllowOutgoingEmailFormat)
                        {
                            StringBuilder sb = new StringBuilder(incidentBox.Document.GeneralBlock.OutgoingEmailFormatSubject, 4096);

                            sb.Replace("[=Title=]", Subject);
                            sb.Replace("[=Ticket=]", IncidentTicket);
                            //sb.Replace("[=Text=]", Body);
                            sb.Replace("[=FirstName=]", Security.CurrentUser.FirstName);
                            sb.Replace("[=LastName=]", Security.CurrentUser.LastName);

                            Subject = sb.ToString();
                        }
                        else
                        {
                            Subject = string.Format("RE: [{0}] {1}",
                                                    IncidentTicket,
                                                    Subject);
                        }
                    }
                    break;

                default:
                    break;
                }

                #endregion

                Pop3Message msg = Create(FullFromEmail, To, Subject, Body, Attachments);

                switch (Mode)
                {
                case EMailClient.IssueMode:
                    #region Issue
                    int IssueId = int.Parse(Params["IssueId"]);

                    IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IssueId));

                    bool AllowEMailRouting = true;

                    EMailRouterIncidentBoxBlock settings = IncidentBoxDocument.Load(incidentBox.IncidentBoxId).EMailRouterBlock;
                    if (!settings.AllowEMailRouting)
                    {
                        AllowEMailRouting = false;
                    }

                    EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal();
                    if (internalPop3Box == null)
                    {
                        AllowEMailRouting = false;
                    }

                    // Register Email Message
                    // OZ: [2007--05-25] Fix Problem Object reference not set to an instance of an object If (internalPop3Box == NULL)
                    int EMailMessageId = EMailMessage.Create(internalPop3Box != null?
                                                             internalPop3Box.EMailRouterPop3BoxId : EMailRouterOutputMessage.FindEMailRouterPublicId(IssueId),
                                                             msg);

                    // Register Forume Node
                    int ThreadNodeId = EMailMessage.AddToIncidentMessage(true, IssueId, EMailMessageId, msg);

                    // Send Message

                    if (AllowEMailRouting)
                    {
                        ArrayList excludedUsers = EMailRouterOutputMessage.Send(IssueId, internalPop3Box, msg, To);
                        SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, IssueId, -1, excludedUsers);
                    }
                    else
                    {
                        FromEmail     = EMailRouterOutputMessage.FindEMailRouterPublicEmail(IssueId);
                        FullFromEmail = string.Format("\"{0} {1}\" <{2}>",
                                                      Security.CurrentUser.LastName,
                                                      Security.CurrentUser.FirstName,
                                                      FromEmail);

                        // Create OutputMessageCreator
                        OutputMessageCreator issueOutput = new OutputMessageCreator(msg,
                                                                                    -1,
                                                                                    FromEmail,
                                                                                    FullFromEmail);

                        // Fill Recipent
                        foreach (string ToItem in To)
                        {
                            issueOutput.AddRecipient(ToItem);
                        }

                        foreach (EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(IssueId))
                        {
                            issueOutput.AddRecipient(exRecipient.EMail);
                        }

                        int emailBoxId = EMail.EMailRouterOutputMessage.FindEMailRouterPublicId(IssueId);

                        //Send Smtp Message
                        foreach (OutputMessage outputMsg in issueOutput.Create())
                        {
                            SmtpClientUtility.SendMessage(OutgoingEmailServiceType.HelpDeskEmailBox, emailBoxId, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                        }

                        ArrayList excludedUsers = new ArrayList();

                        foreach (string ToItem in To)
                        {
                            int emailUserId = DBUser.GetUserByEmail(ToItem, false);
                            if (emailUserId > 0)
                            {
                                excludedUsers.Add(emailUserId);
                            }
                        }

                        SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, IssueId, -1, excludedUsers);
                    }
                    #endregion
                    break;

                case EMailClient.SmtpTestMode:
                    throw new NotImplementedException();
                //OutputMessageCreator smtpTestOutput = new OutputMessageCreator(msg,
                //    -1,
                //    FromEmail,
                //    FullFromEmail);

                //// Fill Recipent
                //foreach (string ToItem in To)
                //{
                //    smtpTestOutput.AddRecipient(ToItem);
                //}

                ////Send Smtp Message
                //foreach (OutputMessage outputMsg in smtpTestOutput.Create())
                //{
                //    //SmtpClientUtility.DirectSendMessage(outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                //    //SmtpBox.SendTestEmail(
                //}
                //break;
                default:
                    #region Default
                    // Create OutputMessageCreator
                    OutputMessageCreator defaultOutput = new OutputMessageCreator(msg,
                                                                                  -1,
                                                                                  FromEmail,
                                                                                  FullFromEmail);

                    // Fill Recipent
                    foreach (string ToItem in To)
                    {
                        defaultOutput.AddRecipient(ToItem);
                    }

                    //Send Smtp Message
                    foreach (OutputMessage outputMsg in defaultOutput.Create())
                    {
                        SmtpClientUtility.SendMessage(OutgoingEmailServiceType.SendFile, null, outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
                    }

                    #endregion
                    break;
                }

                if (Attachments != null)
                {
                    FileStorage.InnerDeleteFolder(Attachments.Id);
                }

                tran.Commit();
            }
        }
Ejemplo n.º 7
0
        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);
                    }
                }
            }
        }