Пример #1
0
        /// <summary>
        /// Deletes the user.
        /// </summary>
        /// <param name="UserId">The user id.</param>
        public static void DeleteUser(int UserId)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                foreach (IncidentBox box in IncidentBox.List())
                {
                    bool bWasModified = false;

                    if (box.Document.GeneralBlock.ResponsiblePool.Contains(UserId))
                    {
                        box.Document.GeneralBlock.ResponsiblePool.Remove(UserId);
                        bWasModified = true;
                    }

                    if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(UserId))
                    {
                        box.Document.EMailRouterBlock.InformationRecipientList.Remove(UserId);
                        bWasModified = true;
                    }

                    if (bWasModified)
                    {
                        IncidentBoxDocument.Save(box.Document);
                    }
                }

                tran.Commit();
            }
        }
Пример #2
0
        public static void Update(IncidentBox box)
        {
            if (!CanModify())
            {
                throw new AccessDeniedException();
            }

            try
            {
                box._srcRow.Update();
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                if (ex.Message.IndexOf("'IX_IncidentBox_1'") != -1)
                {
                    throw new IncidentBoxDuplicateIdentifierMaskException();
                }
                else if (ex.Message.IndexOf("'IX_IncidentBox'") != -1)
                {
                    throw new IncidentBoxDuplicateNameException();
                }
                else
                {
                    throw;
                }
            }
        }
Пример #3
0
        public static IncidentBox Evaluate(IncidentInfo incidentInfo, bool returnDefault)
        {
            IncidentBox defaultBox = null;

            // Load incidentInfo Row
            foreach (IncidentBox box in IncidentBox.ListWithRules())
            {
                if (Evaluate(box.IncidentBoxId, incidentInfo))
                {
                    return(box);
                }

                //if (box.IsDefault)
                //    defaultBox = box;
            }

            // OZ: Find Default Box
            if (defaultBox == null && returnDefault)
            {
                foreach (IncidentBox box in IncidentBox.List())
                {
                    if (box.IsDefault)
                    {
                        defaultBox = box;
                        break;
                    }
                }
            }

            return(defaultBox);
        }
Пример #4
0
        /// <summary>
        /// Replases the user.
        /// </summary>
        /// <param name="OldUserId">The old user id.</param>
        /// <param name="NewUserId">The new user id.</param>
        public static void ReplaseUser(int OldUserId, int NewUserId)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                foreach (IncidentBox box in IncidentBox.List())
                {
                    bool bWasModified = false;

                    if (box.Document.GeneralBlock.AllowControl &&
                        box.Document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser &&
                        box.Document.GeneralBlock.Controller == OldUserId)
                    {
                        box.Document.GeneralBlock.Controller = NewUserId;

                        bWasModified = true;
                    }

                    if (box.Document.GeneralBlock.Manager == OldUserId)
                    {
                        box.Document.GeneralBlock.Manager = NewUserId;

                        bWasModified = true;
                    }

                    if (box.Document.GeneralBlock.ResponsibleAssignType == ResponsibleAssignType.CustomUser &&
                        box.Document.GeneralBlock.Responsible == OldUserId)
                    {
                        box.Document.GeneralBlock.Responsible = NewUserId;
                        bWasModified = true;
                    }

                    if (box.Document.GeneralBlock.ResponsiblePool.Contains(OldUserId))
                    {
                        box.Document.GeneralBlock.ResponsiblePool.Remove(OldUserId);
                        bWasModified = true;
                    }

                    if (box.Document.EMailRouterBlock.InformationRecipientList.Contains(OldUserId))
                    {
                        box.Document.EMailRouterBlock.InformationRecipientList.Remove(OldUserId);
                        bWasModified = true;
                    }

                    if (bWasModified)
                    {
                        IncidentBoxDocument.Save(box.Document);
                    }
                }

                tran.Commit();
            }
        }
Пример #5
0
        /// <summary>
        /// Changes the index of the autodetection.
        /// </summary>
        /// <param name="IncidentBoxId">The incident box id.</param>
        /// <param name="Index">The index.</param>
        public static void ChangeAutodetectionIndex(int IncidentBoxId, int Index)
        {
            using (DbTransaction tran = DbTransaction.Begin())
            {
                IncidentBox[] iBoxList = IncidentBox.ListWithRules();

                // fix Index problem
                if (Index < 0)
                {
                    Index = 0;
                }
                if (Index >= iBoxList.Length)
                {
                    Index = iBoxList.Length - 1;
                }

                int curIncidentBoxIndex = -1;

                for (int index = 0; index < iBoxList.Length; index++)
                {
                    // Set Index as real value
                    iBoxList[index].Index = index;

                    // find IncidentBoxId index
                    if (iBoxList[index].IncidentBoxId == IncidentBoxId)
                    {
                        curIncidentBoxIndex = index;
                    }
                }

                if (curIncidentBoxIndex != -1)
                {
                    iBoxList[curIncidentBoxIndex].Index = Index;

                    // Change Index
                    for (int index = 0; index < iBoxList.Length; index++)
                    {
                        if (index >= Index && index < curIncidentBoxIndex)
                        {
                            iBoxList[index].Index = index + 1;
                        }
                        if (index > curIncidentBoxIndex && index <= Index)
                        {
                            iBoxList[index].Index = index - 1;
                        }
                        IncidentBox.Update(iBoxList[index]);
                    }
                }

                tran.Commit();
            }
        }
Пример #6
0
        public static void Update(IncidentBox box, IncidentBoxDocument document)
        {
            if (!CanModify())
            {
                throw new AccessDeniedException();
            }

            using (Database.DbTransaction tran = Database.DbTransaction.Begin())
            {
                IncidentBox.Update(box);
                IncidentBoxDocument.Save(document);

                // O.R.[2008-12-16]: Recalculate Current Responsible
                DBIncident.RecalculateCurrentResponsibleByIncidentBox(box.IncidentBoxId);

                tran.Commit();
            }
        }
Пример #7
0
        /// <summary>
        /// Gets the outgoing email format body preview.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <returns></returns>
        public static string GetOutgoingEmailFormatBodyPreview(int issueId)
        {
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(issueId));

            string issueTitle  = Incident.GetIncidentTitle(issueId);
            string issueLink   = Alerts2.MakeIssueLink(issueId);
            string issueTicket = TicketUidUtil.Create(incidentBox.IdentifierMask, issueId);

            StringBuilder sb = new StringBuilder(incidentBox.Document.GeneralBlock.OutgoingEmailFormatBody, 4096);

            sb.Replace("[=Title=]", issueTitle);
            sb.Replace("[=Ticket=]", issueTicket);
            //sb.Replace("[=Text=]", node.Text);

            string linkStart = string.Format(CultureInfo.InvariantCulture, "<a href=\"{0}\">", HttpUtility.HtmlAttributeEncode(issueLink));

            sb.Replace("[=Link=]", linkStart);
            sb.Replace("[=/Link=]", "</a>");

            UserLight currentUser = Security.CurrentUser;

            if (currentUser != null)
            {
                sb.Replace("[=FirstName=]", currentUser.FirstName);
                sb.Replace("[=LastName=]", currentUser.LastName);
                sb.Replace("[=Email=]", currentUser.Email);

                using (IDataReader reader = User.GetUserProfile(currentUser.UserID))
                {
                    if (reader.Read())
                    {
                        sb.Replace("[=Phone=]", reader["Phone"].ToString());
                        sb.Replace("[=Fax=]", reader["Fax"].ToString());
                        sb.Replace("[=Mobile=]", reader["Mobile"].ToString());
                        sb.Replace("[=Position=]", reader["Position"].ToString());
                        sb.Replace("[=Department=]", reader["Department"].ToString());
                        sb.Replace("[=Company=]", reader["Company"].ToString());
                        sb.Replace("[=Location=]", reader["Location"].ToString());
                    }
                }
            }

            return(sb.ToString());
        }
Пример #8
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);
        }
Пример #9
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();
        }
Пример #10
0
        /// <summary>
        /// Adds to incident message.
        /// </summary>
        /// <param name="IsInternal">if set to <c>true</c> [is internal].</param>
        /// <param name="IncidentId">The incident id.</param>
        /// <param name="EMailMessageId">The E mail message id.</param>
        /// <param name="msg">The MSG.</param>
        /// <returns></returns>
        public static int AddToIncidentMessage(bool IsInternal, int IncidentId, int EMailMessageId, Pop3Message msg)
        {
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            if (IsInternal)
            {
                // 2007-02-15: OZ: New Messagew Addon
                Issue2.SetNewMessage(IncidentId, false);
                //

                // TODO: If Responsible is Group, set current user as responsible

                return(AddInternalEMail2Incident(IncidentId, EMailMessageId, EMailMessage.GetSenderName(msg), EMailMessage.GetSenderEmail(msg)));
            }
            else
            {
                // 2007-02-15: OZ: New Messagew Addon
                Issue2.SetNewMessage(IncidentId, true);
                //

                return(AddExternalEMail2Incident(IncidentId, EMailMessageId, EMailMessage.GetSenderName(msg), EMailMessage.GetSenderEmail(msg)));
            }
        }
Пример #11
0
        /// <summary>
        /// Determines whether this instance [can delete user] the specified user id.
        /// </summary>
        /// <param name="UserId">The user id.</param>
        /// <returns>
        ///     <c>true</c> if this instance [can delete user] the specified user id; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanDeleteUser(int UserId)
        {
            foreach (IncidentBox box in IncidentBox.List())
            {
                if (box.Document.GeneralBlock.AllowControl &&
                    box.Document.GeneralBlock.ControllerAssignType == ControllerAssignType.CustomUser &&
                    box.Document.GeneralBlock.Controller == UserId)
                {
                    return(false);
                }

                if (box.Document.GeneralBlock.Manager == UserId)
                {
                    return(false);
                }

                if (box.Document.GeneralBlock.ResponsibleAssignType == ResponsibleAssignType.CustomUser &&
                    box.Document.GeneralBlock.Responsible == UserId)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #12
0
        public static void Update(IncidentBox box)
        {
            if(!CanModify())
                throw new AccessDeniedException();

            try
            {
                box._srcRow.Update();
            }
            catch(System.Data.SqlClient.SqlException ex)
            {
                if(ex.Message.IndexOf("'IX_IncidentBox_1'")!=-1)
                    throw new IncidentBoxDuplicateIdentifierMaskException();
                else if(ex.Message.IndexOf("'IX_IncidentBox'")!=-1)
                    throw new IncidentBoxDuplicateNameException();
                else
                    throw;
            }
        }
Пример #13
0
        public static void Update(IncidentBox box, IncidentBoxDocument document)
        {
            if(!CanModify())
                throw new AccessDeniedException();

            using(Database.DbTransaction tran = Database.DbTransaction.Begin())
            {
                IncidentBox.Update(box);
                IncidentBoxDocument.Save(document);

                // O.R.[2008-12-16]: Recalculate Current Responsible
                DBIncident.RecalculateCurrentResponsibleByIncidentBox(box.IncidentBoxId);

                tran.Commit();
            }
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
0
        /// <summary>
        /// Sends the auto reply.
        /// </summary>
        /// <param name="IncidentId">The incident id.</param>
        /// <param name="From">From.</param>
        /// <param name="To">To.</param>
        internal static void SendAutoReply(int IncidentId, string From, string To)
        {
            IncidentBox incidentBox = IncidentBox.Load(Incident.GetIncidentBox(IncidentId));

            if (!incidentBox.Document.EMailRouterBlock.SendAutoReply)
            {
                return;
            }

            Alerts2.Message msg = Alerts2.GetMessage(incidentBox.Document.GeneralBlock.AutoReplyEMailSubjectTemplate,
                                                     incidentBox.Document.GeneralBlock.AutoReplyEMailBodyTemplate,
                                                     SystemEventTypes.Issue_Created,
                                                     IncidentId, null,
                                                     -1,
                                                     Security.CurrentUser.UserID);

            string subject = msg.Subject, body = msg.Body;

            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");

            // OZ Fixed 500 5.3.3 Line too long (in reply to end of DATA command)
            sbMessage.Append(Convert.ToBase64String(Encoding.UTF8.GetBytes(body), Base64FormattingOptions.InsertLineBreaks)).Append("\r\n");

            tmpBuffer = Encoding.ASCII.GetBytes(sbMessage.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);

            OutputMessageCreator outputAutoReply = new OutputMessageCreator(InMsg, IncidentId, From, From);
            outputAutoReply.AddRecipient(To);

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

            foreach (OutputMessage outputMsg in outputAutoReply.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());
                }
            }
        }
Пример #17
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();
                    }
                }
            }
        }