Esempio n. 1
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();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EMailMessageInfo"/> class.
        /// </summary>
        /// <param name="EMailMessageId">The E mail message id.</param>
        protected EMailMessageInfo(int EMailMessageId)
        {
            _EMailMessageId = EMailMessageId;

            // Load Message Row
            EMailMessageRow row = new EMailMessageRow(EMailMessageId);

            ///////////////// Test
            // E:\Util\BlobDataExtractor\output24700.eml
            //System.IO.StreamReader st = new System.IO.StreamReader(@"D:\EMailMessage_72848.eml", System.Text.Encoding.Default);
            //string strmsg = st.ReadToEnd();
            //byte[] buffer = System.Text.Encoding.Default.GetBytes(strmsg);
            //System.IO.MemoryStream memStream = new System.IO.MemoryStream(buffer, 0, buffer.Length, true, true);
            ///////////////

            _created = Database.DBCommon.GetLocalDate(Security.CurrentUser.TimeZoneId, row.Created);

            MemoryStream memStream = new MemoryStream(row.EmlMessage.Length);

            memStream.Write(row.EmlMessage, 0, row.EmlMessage.Length);
            memStream.Position = 0;

            Pop3Message message = new Pop3Message(memStream);

            // Load Headers
            _headers.Add(message.Headers);

            // Extract Html Body
            _htmlBody = ConvertBody(message);

            // Extract Attachments
            _attachments = (AttachmentInfo[])ExtractAttachments(message.MimeEntries).ToArray(typeof(AttachmentInfo));

            _senderEmail = EMailMessage.GetSenderEmail(message);
            _senderName  = EMailMessage.GetSenderName(message);

            _emailBoxId = row.EMailRouterPop3BoxId;
        }
Esempio n. 3
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)));
            }
        }
Esempio n. 4
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);
        }