public void SingleCompanyInvoke()
        {
            if (!License.HelpDesk)
            {
                return;
            }

            // OZ: [2007-01-29] EMailMessageLog
            EmailLogSettings = EMailMessageLogSetting.Current;
            if (EmailLogSettings.IsActive)
            {
                EMailMessageLog.CleanUp(EmailLogSettings.Period);
            }
            else
            {
                EmailLogSettings = null;
            }
            //

            // Process External Box
            foreach (EMailRouterPop3Box pop3Box in EMailRouterPop3Box.ListExternal())
            {
                if (pop3Box.Activity.IsActive)
                {
                    EMailRouterPop3BoxMessageLoader loader = new EMailRouterPop3BoxMessageLoader(pop3Box);

                    loader.Error      += new ExceptionAbortEventHandler(OnMessageLoaderError);
                    loader.NewMessage += new EventHandler(OnNewMessage);


                    loader.ReceiveMessages();
                }
            }

            // Process Internal Box
            EMailRouterPop3Box internalPop3Box = EMailRouterPop3Box.ListInternal();

            if (internalPop3Box != null && internalPop3Box.Activity.IsActive)
            {
                EMailRouterPop3BoxMessageLoader loader = new EMailRouterPop3BoxMessageLoader(internalPop3Box);

                loader.Error      += new ExceptionAbortEventHandler(OnMessageLoaderError);
                loader.NewMessage += new EventHandler(OnNewMessage);

                loader.ReceiveMessages();
            }

            //Process send email from SMTP queue
            //try
            //{
            //    SmtpClientUtility.ProcessSendMessages();
            //}
            //catch (Exception)
            //{
            //    // TODO:
            //    //PortalConfig.SmtpSettings.IsChecked = false;
            //    throw;
            //}
        }
示例#2
0
        /// <summary>
        /// Updates the specified POP3 box.
        /// </summary>
        /// <param name="pop3Box">The POP3 box.</param>
        public static void Update(EMailRouterPop3Box pop3Box)
        {
            if (!CanModify())
            {
                throw new AccessDeniedException();
            }

            pop3Box._srcRow.Update();
        }
示例#3
0
 public static bool CanDeleteUser(int UserId)
 {
     foreach (EMailRouterPop3Box box in EMailRouterPop3Box.ListExternal())
     {
         if (box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator == UserId)
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        /// <summary>
        /// Checks the specified file name.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public static EMailMessageAntiSpamRuleRusult Check(string fileName)
        {
            System.IO.StreamReader st = new System.IO.StreamReader(fileName, System.Text.Encoding.Default);
            string strmsg             = st.ReadToEnd();

            byte[] buffer             = System.Text.Encoding.Default.GetBytes(strmsg);
            System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, true, true);

            Pop3Message msg = new Pop3Message(ms);

            return(Check(EMailRouterPop3Box.ListExternal()[0], msg));
        }
        public static IncidentInfo CreateMapping(int EMailMessageId)
        {
            // Load Message Info
            EMailMessageInfo mi = EMailMessageInfo.Load(EMailMessageId);

            // Load Emal Box
            EMailRouterPop3Box emailBox = EMailRouterPop3Box.Load(mi.EMailRouterPop3BoxId);

            // Load Mapping Handler By EMail Box
            IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);

            // Mapping
            return(mappingHandler.Create(emailBox, EMailMessage.GetPop3Message(EMailMessageId)));
        }
 private void OnMessageLoaderError(object sender, ExceptionAbortEventArgs args)
 {
     if (args.Exception is Pop3Exception ||
         args.Exception is System.Net.Sockets.SocketException ||
         args.Exception is System.IO.IOException)
     {
         EMailRouterPop3BoxMessageLoader loader = (EMailRouterPop3BoxMessageLoader)sender;
         EMailRouterPop3Box.UpdateStatistic(loader.Owner.EMailRouterPop3BoxId, false,
                                            args.Exception.Message, 0);
     }
     else
     {
         Log.WriteError(args.Exception.ToString());
     }
 }
        /// <summary>
        /// Sends the outgoing.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        //public static ArrayList SendOutgoing(int IncidentId, EMailOutgoingMessage email)
        //{
        //    ArrayList retVal = new ArrayList();

        //    // TODO: Not implemented yet

        //    return retVal;
        //}


        /// <summary>
        /// Sends the outgoing.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <returns></returns>
//        public static ArrayList SendOutgoing(int IncidentId, int ThreadNodeId)
//        {
//            // 2007-02-15: OZ: New Messagew Addon
//            Issue2.SetNewMessage(IncidentId, false);
//            //

//            ArrayList retVal = new ArrayList();

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

//            bool AllowEMailRouting = true;

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

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

//            EMailRouterPop3Box pop3Box = internalPop3Box;

//            BaseIbnContainer foContainer = BaseIbnContainer.Create("FileLibrary",string.Format("IncidentId_{0}",IncidentId));
//            ForumStorage forumStorage = (ForumStorage)foContainer.LoadControl("ForumStorage");

//            ForumThreadNodeInfo node = forumStorage.GetForumThreadNode(ThreadNodeId);

//            BaseIbnContainer fsContainer = BaseIbnContainer.Create("FileLibrary",string.Format("ForumNodeId_{0}",node.Id));
//            FileStorage fileStorage = (FileStorage)fsContainer.LoadControl("FileStorage");

//            string IncidentTitle = Incident.GetIncidentTitle(IncidentId);
//            string IncidentTicket = TicketUidUtil.Create(incidentBox.IdentifierMask,IncidentId);

//            string subject;

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

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

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

//            // Create Pop3 Message Stream
//            MemoryStream emlMessage = new MemoryStream();
//            byte[] tmpBuffer = null;

//            #region Fill Pop3 Message Stream
//            // Create Pop3 Message Headers
//            StringBuilder sbHeaders = new StringBuilder();

//            sbHeaders.AppendFormat("Date: {0}", GetEMailCreationDate()).Append("\r\n");
//            sbHeaders.Append("From: [email protected]").Append("\r\n");
//            sbHeaders.Append("To: [email protected]").Append("\r\n");
//            sbHeaders.AppendFormat("Subject: {0}", Rfc822HeaderCollection.Encode2AsciiString(subject)).Append("\r\n");
//            sbHeaders.Append("MIME-Version: 1.0").Append("\r\n");
//            sbHeaders.Append("Content-Type: multipart/mixed; boundary=\"----------7E143249668A83E\"").Append("\r\n");
//            sbHeaders.Append("\r\n");

//            tmpBuffer = Encoding.ASCII.GetBytes(sbHeaders.ToString());
//            emlMessage.Write(tmpBuffer,0, tmpBuffer.Length);

//            // Create Pop3 Message Entry
//            StringBuilder sbMessage = new StringBuilder();

//            sbMessage.Append("------------7E143249668A83E").Append("\r\n");

//            // IF MESSAGE IS PLAIN TEXT
//            //sbMessage.Append("Content-Type: text/plain; charset=utf-8").Append("\r\n");

//            // IF MESSAGE IS HTML TEXT
//            sbMessage.Append("Content-Type: text/html; charset=utf-8").Append("\r\n");

//            sbMessage.Append("Content-Transfer-Encoding: base64").Append("\r\n");
//            sbMessage.Append("\r\n");

//            string FullMessage;

////			if(incidentBox.Document.GeneralBlock.AllowOutgoingEmailFormat)
////			{
////				StringBuilder sb = new StringBuilder(incidentBox.Document.GeneralBlock.OutgoingEmailFormatBody,4096);
////
////				sb.Replace("[=Title=]", IncidentTitle);
////				sb.Replace("[=Ticket=]", IncidentTicket);
////				sb.Replace("[=Text=]", node.Text);
////				sb.Replace("[=FirstName=]", Security.CurrentUser.FirstName);
////				sb.Replace("[=LastName=]", Security.CurrentUser.LastName);
////
////				FullMessage = sb.ToString();
////			}
////			else
////			{
//                FullMessage = node.Text;
////			}

//            sbMessage.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(FullMessage))).Append("\r\n");

//            tmpBuffer = Encoding.ASCII.GetBytes(sbMessage.ToString());
//            emlMessage.Write(tmpBuffer,0, tmpBuffer.Length);

//            Hashtable contentTypeHash = new Hashtable();

//            using(IDataReader reader = ContentType.GetListContentTypes())
//            {
//                while(reader.Read())
//                {
//                    contentTypeHash.Add(((string)reader["Extension"]).ToLower(), (string)reader["ContentTypeString"]);
//                }
//            }


//            // Add Pop3 Message Attachements
//            foreach(Mediachase.IBN.Business.ControlSystem.FileInfo  fileInfo in fileStorage.GetFiles())
//            {
//                StringBuilder sbFile = new StringBuilder();

//                sbFile.Append("------------7E143249668A83E").Append("\r\n");
//                sbFile.AppendFormat("Content-Type: {0}; name=\"{1}\"", fileInfo.FileBinaryContentType, Rfc822HeaderCollection.Encode2AsciiString(fileInfo.Name)).Append("\r\n");
//                sbFile.Append("Content-Transfer-Encoding: base64").Append("\r\n");
//                sbFile.AppendFormat("Content-Disposition: attachment; filename=\"{0}\"", Rfc822HeaderCollection.Encode2AsciiString(fileInfo.Name)).Append("\r\n");
//                sbFile.Append("\r\n");

//                using(MemoryStream fs = new MemoryStream())
//                {
//                    FileStorage.LightLoadFile(fileInfo, fs);
//                    fs.Capacity = (int)fs.Length;

//                    sbFile.Append(Convert.ToBase64String(fs.GetBuffer()));
//                }

//                sbFile.Append("\r\n");

//                tmpBuffer = Encoding.ASCII.GetBytes(sbFile.ToString());
//                emlMessage.Write(tmpBuffer,0, tmpBuffer.Length);
//            }

//            // Add Final Line
//            tmpBuffer = Encoding.ASCII.GetBytes("------------7E143249668A83E--\r\n\r\n");
//            emlMessage.Write(tmpBuffer,0, tmpBuffer.Length);

//            #endregion

//            Pop3Message InMsg = new Pop3Message(emlMessage);

//            // Send Email
//            #region Internal -> Internal Info

//            // Internal -> Internal Info
//            if(AllowEMailRouting)
//            {
//                // 2007-02-12 OZ: "FN LN" <*****@*****.**>
//                string FromEmail = string.Format("\"{0} {1}\" <{2}>",
//                    Security.CurrentUser.FirstName,
//                    Security.CurrentUser.LastName,
//                    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);
//                }

//                foreach(OutputMessage outputMsg in output2Iternal.Create())
//                {
//                    try
//                    {
//                        SmtpClient.SendMessage(outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
//                    }
//                    catch(Exception ex)
//                    {
//                        System.Diagnostics.Trace.WriteLine(ex);
//                        Log.WriteError(ex.ToString());
//                    }
//                }
//            }
//            #endregion

//            #region Internal -> Extrenal
//            // Internal -> Extrenal
//            string fromEMailAddress =  FindEMailRouterPublicEmail(IncidentId);

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

//                OutputMessageCreator output2External = new OutputMessageCreator(InMsg, IncidentId, fromEMailAddress, fromEMailAddress);

//                // Load External Senders
//                //foreach(string exRecipient in EMailMessage.GetExternalSendersByIncidentId(IncidentId))

//                // 2006-12-12 OZ: Load External Senders
//                foreach(EMailIssueExternalRecipient exRecipient in EMailIssueExternalRecipient.List(IncidentId))
//                {
//                    output2External.AddRecipient(exRecipient.EMail);
//                }

//                foreach(OutputMessage outputMsg in output2External.Create())
//                {
//                    try
//                    {
//                        SmtpClient.SendMessage(outputMsg.MailFrom, outputMsg.RcptTo, outputMsg.Subject, outputMsg.Data);
//                    }
//                    catch(Exception ex)
//                    {
//                        System.Diagnostics.Trace.WriteLine(ex);
//                        Log.WriteError(ex.ToString());
//                    }
//                }

//            }
//            #endregion

//            return retVal;
//        }

        public static string FindEMailRouterPublicEmail(int IncidentId)
        {
            int realEMailBoxId = EMailMessage.GetEMailRouterPop3BoxIdByIssueId(IncidentId);

            if (realEMailBoxId == -1)
            {
                EMailRouterPop3Box[] emailBoxList = EMailRouterPop3Box.ListExternal();

                // OZ 2009-01-20 Find EmailBox mapped with IncidentBox
                int incidentBoxId = Incident.GetIncidentBox(IncidentId);

                foreach (EMailRouterPop3Box emailBox in emailBoxList)
                {
                    if (emailBox.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId == incidentBoxId)
                    {
                        return(emailBox.EMailAddress);
                    }
                }
                //

                // try to find active
                foreach (EMailRouterPop3Box emailBox in emailBoxList)
                {
                    if (emailBox.Activity.IsActive)
                    {
                        return(emailBox.EMailAddress);
                    }
                }

                if (emailBoxList.Length > 0)
                {
                    return(emailBoxList[0].EMailAddress);
                }

                if (Security.CurrentUser != null)
                {
                    return(Security.CurrentUser.Email);
                }

                return(Alerts2.AlertSenderEmail);
            }
            else
            {
                EMailRouterPop3Box emailBox = EMailRouterPop3Box.Load(realEMailBoxId);
                return(emailBox.EMailAddress);
            }
        }
示例#8
0
        public static void ReplaseUser(int OldUserId, int NewUserId)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                foreach (EMailRouterPop3Box box in EMailRouterPop3Box.ListExternal())
                {
                    EMailRouterPop3BoxSettings settings = box.Settings;
                    if (settings.DefaultEMailIncidentMappingBlock.DefaultCreator == OldUserId)
                    {
                        settings.DefaultEMailIncidentMappingBlock.DefaultCreator = NewUserId;
                        EMailRouterPop3BoxSettings.Save(settings);
                    }
                }

                tran.Commit();
            }
        }
示例#9
0
        /// <summary>
        /// Creates the new incident.
        /// </summary>
        /// <param name="EMailMessageId">The E mail message id.</param>
        /// <param name="emailBox">The email box.</param>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        public static int CreateNewIncident(int EMailMessageId, EMailRouterPop3Box emailBox, Pop3Message msg)
        {
            IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);

            // Step. Mapping
            IncidentInfo incidentInfo = mappingHandler.Create(emailBox, msg);

            // Set Creator
            UserLight prevUser = LogOnCreator(incidentInfo.CreatorId, msg);

            incidentInfo.CreatorId = Security.CurrentUser.UserID;

            // Step. Evaluate IncidentBox
            IncidentBox incidentBox = null;

            if (incidentInfo.IncidentBoxId != -1)
            {
                incidentBox = IncidentBox.Load(incidentInfo.IncidentBoxId);
            }
            else
            {
                incidentBox = IncidentBoxRule.Evaluate(incidentInfo);
            }

            // Step. Create Incident
            int IncidentId = Incident.CreateFromEmail(incidentInfo.Title,
                                                      incidentInfo.Description,
                                                      incidentInfo.ProjectId,
                                                      incidentInfo.TypeId,
                                                      incidentInfo.PriorityId,
                                                      incidentInfo.SeverityId,
                                                      incidentBox.Document.GeneralBlock.TaskTime,
                                                      incidentBox.Document.GeneralBlock.ExpectedDuration,
                                                      incidentBox.Document.GeneralBlock.ExpectedResponseTime,
                                                      incidentBox.Document.GeneralBlock.ExpectedAssignTime,
                                                      incidentInfo.GeneralCategories,
                                                      incidentInfo.IncidentCategories,
                                                      incidentBox.IncidentBoxId,
                                                      EMailMessageId,
                                                      incidentInfo.OrgUid,
                                                      incidentInfo.ContactUid);

            return(IncidentId);
        }
示例#10
0
        /// <summary>
        /// Finds the E mail router public id.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <returns></returns>
        public static int FindEMailRouterPublicId(int IncidentId)
        {
            int realEMailBoxId = EMailMessage.GetEMailRouterPop3BoxIdByIssueId(IncidentId);

            if (realEMailBoxId == -1)
            {
                EMailRouterPop3Box[] emailBoxList = EMailRouterPop3Box.ListExternal();

                // OZ 2009-01-20 Find EmailBox mapped with IncidentBox
                int incidentBoxId = Incident.GetIncidentBox(IncidentId);

                foreach (EMailRouterPop3Box emailBox in emailBoxList)
                {
                    if (emailBox.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId == incidentBoxId)
                    {
                        return(emailBox.EMailRouterPop3BoxId);
                    }
                }
                //

                // try to find firt active
                foreach (EMailRouterPop3Box emailBox in emailBoxList)
                {
                    if (emailBox.Activity.IsActive)
                    {
                        return(emailBox.EMailRouterPop3BoxId);
                    }
                }
                //

                if (emailBoxList.Length > 0)
                {
                    return(emailBoxList[0].EMailRouterPop3BoxId);
                }

                return(-1);
            }
            else
            {
                return(realEMailBoxId);
            }
        }
示例#11
0
        public static void OpenEml(int IncidentId, int EMailMessageId, Stream outputStream)
        {
            Pop3Message message     = EMailMessage.GetPop3Message(EMailMessageId);
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            EMailRouterPop3Box emailBox = EMailRouterPop3Box.ListInternal();

            string SenderName = EMailMessage.GetSenderName(message);

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

            OutputMessageCreator output = new OutputMessageCreator(message, IncidentId, emailBox.EMailAddress, FromEmail);

            output.AddRecipient(Security.CurrentUser.UserID);

            string Subject = (message.Subject == null?string.Empty:message.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);
            }


            OutputMessage outputMsg = (OutputMessage)output.Create()[0];

            outputStream.Write(outputMsg.Data, 0, outputMsg.Data.Length);

            outputStream.Flush();
        }
示例#12
0
 public static ArrayList Send(int IncidentId, EMailRouterPop3Box pop3Box, Pop3Message InMsg)
 {
     return(Send(IncidentId, pop3Box, InMsg, null));
 }
示例#13
0
        public static ArrayList Send(int IncidentId, int EMailMessageId)
        {
            EMailMessageRow row = new EMailMessageRow(EMailMessageId);

            return(Send(IncidentId, EMailRouterPop3Box.Load(row.EMailRouterPop3BoxId), EMailMessage.GetPop3Message(row.EmlMessage)));
        }
 protected virtual int[] GetIncidentCategories(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
 {
     return((int[])box.Settings.DefaultEMailIncidentMappingBlock.IncidentCategories.ToArray(typeof(int)));
 }
示例#15
0
        /// <summary>
        /// Determines whether this instance can activate the specified E mail router POP3 box I.
        /// </summary>
        /// <param name="EMailRouterPop3BoxI">The E mail router POP3 box I.</param>
        /// <returns>
        ///     <c>true</c> if this instance can activate the specified E mail router POP3 box I; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanActivate(int EMailRouterPop3BoxI)
        {
            EMailRouterPop3Box box = EMailRouterPop3Box.Load(EMailRouterPop3BoxI);

            return(box.IsInternal || box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator != -1);
        }
示例#16
0
        public void ReceiveMessages()
        {
            try
            {
                Pop3Connection connection = new Pop3Connection();

                //IPHostEntry hostInfo = Dns.GetHostEntry(Owner.Server);
                IPAddress[] addresses = Dns.GetHostAddresses(Owner.Server);

                IPEndPoint pop3ServerEndPoint = new IPEndPoint(addresses[0], Owner.Port);

                if (this.Owner.SecureConnectionType == Pop3SecureConnectionType.Ssl)
                {
                    connection.OpenSsl(pop3ServerEndPoint, Owner.Server);
                }
                else
                {
                    connection.Open(pop3ServerEndPoint);
                }

                if (this.Owner.SecureConnectionType == Pop3SecureConnectionType.Tls)
                {
                    connection.Stls(Owner.Server);
                }

                connection.User(Owner.Login);
                connection.Pass(Owner.Pass);

                Pop3Stat stat = connection.Stat();

                EMailRouterPop3Box.UpdateStatistic(this.Owner.EMailRouterPop3BoxId,
                                                   true,
                                                   string.Empty, stat.MessageCout);


                if (stat.MessageCout > 0)
                {
                    // Step 3. Request uidl.
                    Pop3UIDInfoList uidList = connection.Uidl();

                    foreach (Pop3UIDInfo uidItem in uidList)
                    {
                        try
                        {
                            // Step 4. Request message.
                            Pop3Message msg = connection.Retr(uidItem.ID);

                            // Step 5. Process message.
                            RaiseNewMessageEvent(msg);

                            // Step 6. Delete message from server.
                            connection.Dele(uidItem.ID);
                        }
                        catch (Exception ex)
                        {
                            if (RaiseErrorEvent(ex))
                            {
                                throw;
                            }
                        }
                    }
                }

                connection.Quit();
            }
            catch (Exception ex)
            {
                if (RaiseErrorEvent(ex))
                {
                    throw;
                }
            }
        }
示例#17
0
        /// <summary>
        /// Checks the specified email box.
        /// </summary>
        /// <param name="emailBox">The email box.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public static EMailMessageAntiSpamRuleRusult Check(EMailRouterPop3Box emailBox, Pop3Message message)
        {
            // 2007-01-09: Check Empty From and Sender
            if (message.Sender == null && message.From == null || message.To == null)
            {
                return(EMailMessageAntiSpamRuleRusult.Deny);
            }

            EMailMessageAntiSpamRule[] antiSpamRules = EMailMessageAntiSpamRule.List();

            // Load Rules
            //EMailMessageAntiSpamRule[] antiSpamRules = _antiSpamRules;

            // Check Rules

            foreach (EMailMessageAntiSpamRule rule in antiSpamRules)
            {
                if (((EMailMessageAntiSpamRuleType)rule.RuleType) != EMailMessageAntiSpamRuleType.Service)
                {
                    string KeyValue = GetStringFromEmailByKey(message, rule.Key);

                    if (KeyValue != null)
                    {
                        switch ((EMailMessageAntiSpamRuleType)rule.RuleType)
                        {
                        case EMailMessageAntiSpamRuleType.Contains:
                            foreach (string ContainsSubStr in rule.Value.Split(';'))
                            {
                                string TrimContainsSubStr = ContainsSubStr.Trim();
                                if (TrimContainsSubStr != string.Empty)
                                {
                                    if (TrimContainsSubStr.IndexOfAny(new char[] { '*', '?' }) != -1)
                                    {
                                        if (Pattern.Match(KeyValue, TrimContainsSubStr))
                                        {
                                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                                        }
                                    }
                                    else
                                    {
                                        if (KeyValue.IndexOf(TrimContainsSubStr) != -1)
                                        {
                                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                                        }
                                    }
                                }
                            }
                            break;

                        case EMailMessageAntiSpamRuleType.IsEqual:
                            if (string.Compare(KeyValue, rule.Value, true) == 0)
                            {
                                return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                            }
                            break;

                        case EMailMessageAntiSpamRuleType.RegexMatch:
                            Match match = Regex.Match(KeyValue, rule.Value);
                            if ((match.Success && (match.Index == 0)) && (match.Length == KeyValue.Length))
                            {
                                return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    string FromEmail = EMailMessage.GetSenderEmail(message);

                    switch (rule.Key)
                    {
                    case BlackListServiceName:
                        if (BlackListItem.Contains(FromEmail))
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case WhiteListServiceName:
                        if (WhiteListItem.Contains(FromEmail))
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case TicketServiceName:
                        if (message.Subject != null && TicketUidUtil.LoadFromString(message.Subject) != string.Empty)
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;

                    case IncidentBoxRulesServiceName:
                        // Step 1. Get Incident Info
                        IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);
                        IncidentInfo          incidentInfo   = mappingHandler.Create(emailBox, message);

                        // Step 2. Evaluate IncidentBoxRules
                        IncidentBox box = IncidentBoxRule.Evaluate(incidentInfo, false);
                        if (box != null)
                        {
                            return(rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny);
                        }
                        break;
                    }
                }
            }

            return(EMailMessageAntiSpamRuleRusult.Pending);
        }
示例#18
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();
            }
        }
示例#19
0
        /// <summary>
        /// Updates the specified POP3 box.
        /// </summary>
        /// <param name="pop3Box">The POP3 box.</param>
        public static void Update(EMailRouterPop3Box pop3Box)
        {
            if(!CanModify())
                throw new AccessDeniedException();

            pop3Box._srcRow.Update();
        }
示例#20
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();
            }
        }
示例#21
0
 public static ArrayList Send(int IncidentId, EMailRouterPop3Box pop3Box, Pop3Message InMsg)
 {
     return Send(IncidentId, pop3Box, InMsg, null);
 }
示例#22
0
        public static void Open(int IncidentId, int EMailMessageId, Stream outputStream)
        {
            System.Reflection.Assembly asm = typeof(MsgMessage).Assembly;

            Pop3Message message     = EMailMessage.GetPop3Message(EMailMessageId);
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            EMailRouterPop3Box box = EMailRouterPop3Box.ListInternal();

            string receiver = Security.CurrentUser.Email;            //EMailMessage.GetSenderEmail(message);
            string sender   = box.EMailAddress;

            using (Stream stream = asm.GetManifestResourceStream("Mediachase.IBN.Business.Resources.template.msg"))
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    using (MsgHelper helper = new MsgHelper(stream))
                    {
                        helper.SetSenderEmail(sender);

                        //string SenderName = EMailMessage.GetSenderName(message);
                        //helper.SetSenderName(SenderName==string.Empty?sender:SenderName);
                        helper.SetSenderName(sender);

                        string IncidentTitle  = Incident.GetIncidentTitle(IncidentId);
                        string IncidentTicket = TicketUidUtil.Create(incidentBox.IdentifierMask, IncidentId);

                        string Subject = (message.Subject == null?string.Empty:message.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)
                        {
                            Subject = string.Format("[{0}] {1}", TicketUidUtil.Create(incidentBox.IdentifierMask, IncidentId), Subject);
                        }

                        helper.SetReceiverName(Security.CurrentUser.DisplayName);
                        helper.SetDisplayTo(receiver);
                        helper.SetReceiverEmail(receiver);
                        helper.SetCreationTimes(DateTime.UtcNow);

                        helper.SetSubject(Subject);
                        helper.SetBody(message.BodyText);
                        if (message.BodyHtml == null || message.BodyHtml.Trim() == String.Empty)
                        {
                            helper.SetHtmlBody(message.BodyText);
                        }
                        else
                        {
                            helper.SetHtmlBody(message.BodyHtml);
                        }

                        helper.Commit();

                        helper.createMSG(memStream);
                        memStream.Flush();
                        memStream.Seek(0, SeekOrigin.Begin);

                        const int bufLen = 1024;
                        byte[]    buffer = new byte[bufLen];
                        int       bytesRead;
                        while ((bytesRead = memStream.Read(buffer, 0, bufLen)) > 0)
                        {
                            outputStream.Write(buffer, 0, bytesRead);
                        }
                        outputStream.Flush();
                    }
                }
            }
        }
示例#23
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);
        }
        public IncidentInfo Create(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
        {
            IncidentInfo retVal = new IncidentInfo();

            retVal.CreatorId = box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator;

            retVal.EMailBox = box.EMailRouterPop3BoxId;

            retVal.Title = msg.Subject == null?string.Empty:msg.Subject;

            if (retVal.Title == string.Empty)
            {
                // Set Default Inicdent Title if subject is empty
                string SenderID = EMailMessage.GetSenderName(msg);
                if (SenderID == string.Empty)
                {
                    SenderID = EMailMessage.GetSenderEmail(msg);
                }
                retVal.Title = string.Format("{0} ({1})", SenderID, DateTime.Now.ToString("d"));
            }

            // OZ: 2008-07-30 Added description defenition rules
            if (box.Settings.DefaultEMailIncidentMappingBlock.DescriptionId == -1)
            {
                retVal.Description = string.Empty;
                retVal.EMailBody   = EMailMessageInfo.ExtractTextFromHtml(msg);
            }
            else
            {
                retVal.Description = EMailMessageInfo.ExtractTextFromHtml(msg);
                retVal.EMailBody   = retVal.Description;
            }
            //

            int priorityId = GetPriorityId(box, msg);

            if (priorityId < 0)             // <0 From Email
            {
                retVal.PriorityId = 500;

                string importance = msg.Importance;
                if (importance != null)
                {
                    switch (importance.ToLower())
                    {
                    case "low":
                        retVal.PriorityId = 0;
                        break;

                    case "normal":
                        retVal.PriorityId = 500;
                        break;

                    case "high":
                        retVal.PriorityId = 750;
                        break;
                    }
                }
            }
            else
            {
                retVal.PriorityId = priorityId;
            }


            retVal.MailSenderEmail = EMailMessage.GetSenderEmail(msg);

            retVal.SeverityId = GetSeverityId(box, msg);
            retVal.TypeId     = GetTypeId(box, msg);
            retVal.GeneralCategories.AddRange(GetGeneralCategories(box, msg));
            retVal.IncidentCategories.AddRange(GetIncidentCategories(box, msg));

            // OZ: 2007-01-11
            retVal.ProjectId     = box.Settings.DefaultEMailIncidentMappingBlock.ProjectId;
            retVal.IncidentBoxId = box.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId;

            // OZ: 2007-01-22
            retVal.OrgUid     = box.Settings.DefaultEMailIncidentMappingBlock.OrgUid;
            retVal.ContactUid = box.Settings.DefaultEMailIncidentMappingBlock.ContactUid;

            return(retVal);
        }
 protected virtual int GetTypeId(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
 {
     return(box.Settings.DefaultEMailIncidentMappingBlock.TypeId);
 }
示例#26
0
 protected virtual int GetTypeId(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
 {
     return box.Settings.DefaultEMailIncidentMappingBlock.TypeId;
 }
示例#27
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);
                    }
                }
            }
        }
示例#28
0
        public IncidentInfo Create(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
        {
            IncidentInfo retVal = new IncidentInfo();

            retVal.CreatorId = box.Settings.DefaultEMailIncidentMappingBlock.DefaultCreator;

            retVal.EMailBox = box.EMailRouterPop3BoxId;

            retVal.Title = msg.Subject==null?string.Empty:msg.Subject;

            if(retVal.Title==string.Empty)
            {
                // Set Default Inicdent Title if subject is empty
                string SenderID = EMailMessage.GetSenderName(msg);
                if(SenderID==string.Empty)
                    SenderID = EMailMessage.GetSenderEmail(msg);
                retVal.Title = string.Format("{0} ({1})", SenderID, DateTime.Now.ToString("d"));
            }

            // OZ: 2008-07-30 Added description defenition rules
            if (box.Settings.DefaultEMailIncidentMappingBlock.DescriptionId == -1)
            {
                retVal.Description = string.Empty;
                retVal.EMailBody = EMailMessageInfo.ExtractTextFromHtml(msg);

            }
            else
            {
                retVal.Description = EMailMessageInfo.ExtractTextFromHtml(msg);
                retVal.EMailBody = retVal.Description;
            }
            //

            int priorityId = GetPriorityId(box, msg);

            if (priorityId < 0) // <0 From Email
            {
                retVal.PriorityId = 500;

                string importance = msg.Importance;
                if (importance != null)
                {
                    switch (importance.ToLower())
                    {
                        case "low":
                            retVal.PriorityId = 0;
                            break;
                        case "normal":
                            retVal.PriorityId = 500;
                            break;
                        case "high":
                            retVal.PriorityId = 750;
                            break;
                    }
                }
            }
            else
            {
                retVal.PriorityId = priorityId;
            }

            retVal.MailSenderEmail = EMailMessage.GetSenderEmail(msg);

            retVal.SeverityId = GetSeverityId(box, msg);
            retVal.TypeId = GetTypeId(box, msg);
            retVal.GeneralCategories.AddRange(GetGeneralCategories(box, msg));
            retVal.IncidentCategories.AddRange(GetIncidentCategories(box, msg));

            // OZ: 2007-01-11
            retVal.ProjectId = box.Settings.DefaultEMailIncidentMappingBlock.ProjectId;
            retVal.IncidentBoxId = box.Settings.DefaultEMailIncidentMappingBlock.IncidentBoxId;

            // OZ: 2007-01-22
            retVal.OrgUid = box.Settings.DefaultEMailIncidentMappingBlock.OrgUid;
            retVal.ContactUid = box.Settings.DefaultEMailIncidentMappingBlock.ContactUid;

            return retVal;
        }
 public EMailRouterPop3BoxMessageLoader(EMailRouterPop3Box pop3Box)
 {
     _pop3Box = pop3Box;
 }
示例#30
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;
        }
示例#31
0
 public EMailRouterPop3BoxMessageLoader(EMailRouterPop3Box pop3Box)
 {
     _pop3Box = pop3Box;
 }
示例#32
0
 protected virtual int[] GetIncidentCategories(EMailRouterPop3Box box, Mediachase.Net.Mail.Pop3Message msg)
 {
     return (int[])box.Settings.DefaultEMailIncidentMappingBlock.IncidentCategories.ToArray(typeof(int));
 }
示例#33
0
        /// <summary>
        /// Checks the specified email box.
        /// </summary>
        /// <param name="emailBox">The email box.</param>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public static EMailMessageAntiSpamRuleRusult Check(EMailRouterPop3Box emailBox, Pop3Message message)
        {
            // 2007-01-09: Check Empty From and Sender
            if (message.Sender == null && message.From == null || message.To == null)
                return EMailMessageAntiSpamRuleRusult.Deny;

            EMailMessageAntiSpamRule[] antiSpamRules = EMailMessageAntiSpamRule.List();

            // Load Rules
            //EMailMessageAntiSpamRule[] antiSpamRules = _antiSpamRules;

            // Check Rules

            foreach (EMailMessageAntiSpamRule rule in antiSpamRules)
            {
                if (((EMailMessageAntiSpamRuleType)rule.RuleType) != EMailMessageAntiSpamRuleType.Service)
                {
                    string KeyValue = GetStringFromEmailByKey(message, rule.Key);

                    if (KeyValue != null)
                    {
                        switch ((EMailMessageAntiSpamRuleType)rule.RuleType)
                        {
                            case EMailMessageAntiSpamRuleType.Contains:
                                foreach (string ContainsSubStr in rule.Value.Split(';'))
                                {
                                    string TrimContainsSubStr = ContainsSubStr.Trim();
                                    if (TrimContainsSubStr != string.Empty)
                                    {
                                        if (TrimContainsSubStr.IndexOfAny(new char[] { '*', '?' }) != -1)
                                        {
                                            if (Pattern.Match(KeyValue, TrimContainsSubStr))
                                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                                        }
                                        else
                                        {
                                            if (KeyValue.IndexOf(TrimContainsSubStr) != -1)
                                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                                        }
                                    }
                                }
                                break;
                            case EMailMessageAntiSpamRuleType.IsEqual:
                                if (string.Compare(KeyValue, rule.Value, true) == 0)
                                    return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                                break;
                            case EMailMessageAntiSpamRuleType.RegexMatch:
                                Match match = Regex.Match(KeyValue, rule.Value);
                                if ((match.Success && (match.Index == 0)) && (match.Length == KeyValue.Length))
                                    return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                                break;
                        }
                    }
                }
                else
                {
                    string FromEmail = EMailMessage.GetSenderEmail(message);

                    switch (rule.Key)
                    {
                        case BlackListServiceName:
                            if (BlackListItem.Contains(FromEmail))
                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                            break;
                        case WhiteListServiceName:
                            if (WhiteListItem.Contains(FromEmail))
                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                            break;
                        case TicketServiceName:
                            if (message.Subject != null && TicketUidUtil.LoadFromString(message.Subject) != string.Empty)
                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                            break;
                        case IncidentBoxRulesServiceName:
                            // Step 1. Get Incident Info
                            IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);
                            IncidentInfo incidentInfo = mappingHandler.Create(emailBox, message);

                            // Step 2. Evaluate IncidentBoxRules
                            IncidentBox box = IncidentBoxRule.Evaluate(incidentInfo, false);
                            if (box != null)
                                return rule.Accept ? EMailMessageAntiSpamRuleRusult.Accept : EMailMessageAntiSpamRuleRusult.Deny;
                            break;
                    }

                }
            }

            return EMailMessageAntiSpamRuleRusult.Pending;
        }
示例#34
0
        /// <summary>
        /// Creates the new incident.
        /// </summary>
        /// <param name="EMailMessageId">The E mail message id.</param>
        /// <param name="emailBox">The email box.</param>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        public static int CreateNewIncident(int EMailMessageId, EMailRouterPop3Box emailBox, Pop3Message msg)
        {
            IEMailIncidentMapping mappingHandler = EMailIncidentMappingHandler.LoadHandler(emailBox.Settings.SelectedHandlerId);

            // Step. Mapping
            IncidentInfo incidentInfo = mappingHandler.Create(emailBox, msg);

            // Set Creator
            UserLight prevUser = LogOnCreator(incidentInfo.CreatorId, msg);

            incidentInfo.CreatorId = Security.CurrentUser.UserID;

            // Step. Evaluate IncidentBox
            IncidentBox incidentBox = null;

            if (incidentInfo.IncidentBoxId != -1)
                incidentBox = IncidentBox.Load(incidentInfo.IncidentBoxId);
            else
                incidentBox = IncidentBoxRule.Evaluate(incidentInfo);

            // Step. Create Incident
            int IncidentId = Incident.CreateFromEmail(incidentInfo.Title,
                incidentInfo.Description,
                incidentInfo.ProjectId,
                incidentInfo.TypeId,
                incidentInfo.PriorityId,
                incidentInfo.SeverityId,
                incidentBox.Document.GeneralBlock.TaskTime,
                incidentBox.Document.GeneralBlock.ExpectedDuration,
                incidentBox.Document.GeneralBlock.ExpectedResponseTime,
                incidentBox.Document.GeneralBlock.ExpectedAssignTime,
                incidentInfo.GeneralCategories,
                incidentInfo.IncidentCategories,
                incidentBox.IncidentBoxId,
                EMailMessageId,
                incidentInfo.OrgUid,
                incidentInfo.ContactUid);

            return IncidentId;
        }