Esempio n. 1
0
        private void ParseAttachment(ref EMailAttachment Attachment, string[] AttachmentLines)
        {
            int headerEndLine = FindHeaderEnd(AttachmentLines);

            ParseAttachmentHeaders(ref Attachment, GetHeaderLines(AttachmentLines, headerEndLine));
            ParseAttachmentContent(ref Attachment, GetBodyLines(AttachmentLines, headerEndLine));
        }
        public bool SendMail(FlightWeatherResponse flightWeatherResponse)
        {
            string body    = GetBody(flightWeatherResponse);
            var    subject = MailText.EmailSubject(flightWeatherResponse);

            using (MMT_WEBS_InteractionManagerSoapClient client = new MMT_WEBS_InteractionManagerSoapClient())
            {
                if (string.IsNullOrWhiteSpace(body))
                {
                    return(false);
                }
                EMailAttachment[] attachments = null;
                if (flightWeatherResponse.ItineraryFlightStatus.FlightStatus == "S")
                {
                    try
                    {
                        attachments = new EMailAttachment[1];
                        EMailAttachment attachment = new EMailAttachment
                        {
                            Content   = MailManager.GetETicketBytes(flightWeatherResponse.ItineraryQueue),
                            ContentId = "E-Ticket",
                            FileName  = flightWeatherResponse.ItineraryQueue.BookingID + ".E-Ticket.pdf"
                        };
                        attachments[0] = attachment;
                    }
                    catch (Exception exception)
                    {
                        ErrorLog.WriteErrorLog(exception, flightWeatherResponse.ItineraryQueue.BookingID, "MMT_WS_FlightWeather");
                    }
                }

                EMailMessage mailMessage = new EMailMessage
                {
                    To            = new[] { flightWeatherResponse.ItineraryQueue.BookingDetails.Email },
                    Subject       = subject,
                    Source        = MailText.Source,
                    ReferenceNo   = flightWeatherResponse.ItineraryQueue.BookingID,
                    IsBodyHtml    = true,
                    Body          = body,
                    From          = MailText.From,
                    ReferenceType = "BookingID",
                    RequestDate   = DateTime.Now,
                    Attachment    = attachments,
                    emailType     = EmailType.General
                };
                string errorMessage = string.Empty;
                return(client.SendEmail(mailMessage, ref errorMessage));
            }
        }
Esempio n. 3
0
        private void ParseMultipartAlternativeViews(string[] ViewsCollectionLines, int[] BoundaryPositions, ref EMailBodyAlternateView[] Views, ref EMailAttachment[] Attachments)
        {
            EMailBodyAlternateView[] parsedViews       = null;
            EMailAttachment[]        parsedAttachments = null;

            if (BoundaryPositions != null && BoundaryPositions.Length > 2)
            {
                for (int i = 0; i < BoundaryPositions.Length - 1;)
                {
                    string[] viewLines = GetStringArrayPart(ViewsCollectionLines, BoundaryPositions[i] + 1, BoundaryPositions[++i] - 1);
                    ParseNestedContent(viewLines, ref parsedViews, ref parsedAttachments);
                }
            }

            if (Views == null)
            {
                Views = new EMailBodyAlternateView[0];
            }
            if (Attachments == null)
            {
                Attachments = new EMailAttachment[0];
            }
            if (parsedViews == null)
            {
                parsedViews = new EMailBodyAlternateView[0];
            }
            if (parsedAttachments == null)
            {
                parsedAttachments = new EMailAttachment[0];
            }

            EMailBodyAlternateView[] newViewsCollection = new EMailBodyAlternateView[Views.Length + parsedViews.Length];
            Array.Copy(Views, newViewsCollection, Views.Length);
            Array.Copy(parsedViews, 0, newViewsCollection, Views.Length, parsedViews.Length);

            EMailAttachment[] newAttachmentsCollection = new EMailAttachment[Attachments.Length + parsedAttachments.Length];
            Array.Copy(Attachments, newAttachmentsCollection, Attachments.Length);
            Array.Copy(parsedAttachments, 0, newAttachmentsCollection, Attachments.Length, parsedAttachments.Length);

            Views       = newViewsCollection;
            Attachments = newAttachmentsCollection;

            return;
        }
Esempio n. 4
0
        public override bool LoadModel(MassEmail em, EmailTemplateViewModel template, CompanyUser user)
        {
            LoadBaseFeature(em, template, user);
            //this.DateCycle(em, template, (em, template, dt) => {
            //    template.Models.Add(dt, _mailRepo.ReportRepository.EmailWeekInvoice(dt, _companyid,user));
            //});

            string sql    = ReplaceMacro(em.SQLCommand, ExecModel);
            var    attach = new EMailAttachment();

            attach.Content     = _mailRepo.ProduceFlatCSV(sql).Result;
            attach.ContentType = "text/csv";
            attach.Name        = ReplaceMacro(em.Name, ExecModel);
            attach.Name        = Translit.cyr2lat(attach.Name) + ".csv";
            template.Attachments.Add(attach);
            template.JustAttachment = true;

            //template.Models.Add(dt, _mailRepo.ReportRepository.EmailWeekInvoice(dt, _companyid, user));
            return(true);
        }
Esempio n. 5
0
        public override bool LoadModel(MassEmail em, EmailTemplateViewModel template, CompanyUser user)
        {
            LoadBaseFeature(em, template, user);
            //this.DateCycle(em, template, (em, template, dt) => {
            //    template.Models.Add(dt, _mailRepo.ReportRepository.EmailWeekInvoice(dt, _companyid,user));
            //});

            //string sql = ReplaceMacro(em.SQLCommand, ExecModel);
            string reportname = em.SQLCommand;
            var    attach     = new EMailAttachment();
            var    result     = _mailRepo.ProduceExcel(reportname, ExecModel.DateFrom, ExecModel.DateTo, _companyid).GetAwaiter().GetResult();

            attach.Content     = result.FileContents;
            attach.ContentType = result.ContentType;
            attach.Name        = result.FileDownloadName;

            template.Attachments.Add(attach);
            template.JustAttachment = true;

            //template.Models.Add(dt, _mailRepo.ReportRepository.EmailWeekInvoice(dt, _companyid, user));
            return(true);
        }
Esempio n. 6
0
        private void btnAttachRemove_Click(object sender, EventArgs e)
        {
            if (lbAttachments.SelectedItem == null || lbAttachments.SelectedItem.ToString() == string.Empty)
            {
                return;
            }
            EMailAttachment[] tmp = new EMailAttachment[message.Attachments.Length - 1];
            int copied            = 0;

            for (int i = 0; i < message.Attachments.Length; ++i)
            {
                if (message.Attachments[i].FileName != lbAttachments.SelectedItem.ToString())
                {
                    tmp[i + copied] = message.Attachments[i];
                }
                else
                {
                    copied = -1;
                }
            }
            message.Attachments = tmp;
            this.FillAttachmentsListBox();
        }
    // Update is called once per frame
    void Update()
    {
        curEMail = emailList[currentEmailListIndex];

        switch (MailState)
        {
        case MailMode.Inactive:

            CheckForNewMail();

            break;

        case MailMode.Loading:

            mailListBgd.texture = transitionScreenFrames[curtransitionScreenFramesIndex];

            if (Time.time - loadingDelayRefTime > loadingDelayTime)
            {
                mailListBgd.enabled                 = true;
                messengerMainScreen.materials       = blankScreenMaterial;
                messengerAttachmentScreen.materials = blankScreenMaterial;

                if (Time.time - transitionScreenFrameRefTime > transitionScreenFrameTime)
                {
                    if (curtransitionScreenFramesIndex < transitionScreenFrames.Count - 1)
                    {
                        curtransitionScreenFramesIndex++;
                        transitionScreenFrameRefTime = Time.time;
                    }
                    else
                    {
                        ShowEMail(true);

                        DetermineVisibleTextOfCurrentMessage();

                        MailState = MailMode.ViewingMessage;
                    }
                }
            }

            break;

        case MailMode.ViewingMessage:

            if (curEMail.attachments.Count > 0)
            {
                curAttachmentIcon = mailAttachmentsIcons[curAttachmentIndex];
                curAttachment     = curEMail.attachments[curAttachmentIndex];

                mailAttachmentSelector.enabled = true;
                mailAttachmentSelector.rectTransform.anchoredPosition = curAttachmentIcon.rectTransform.anchoredPosition;
                FlashAttachmentIcon();

                attachmentNameText.text    = curAttachment.attachmentShortDescription;
                attachmentNameText.enabled = true;
            }
            else
            {
                mailAttachmentSelector.enabled = false;

                attachmentNameText.text    = "";
                attachmentNameText.enabled = false;
            }

            curEMail = emailList[currentEmailListIndex];
            AssignTextAndBgd(curEMail, currentEmailListIndex, currentListVisibleIndex);
            ShowAttachments(curEMail, true);

            break;

        case MailMode.ViewingAttachment:

            if (curAttachment != null)
            {
                if (curAttachment.pointsOfInterest.Count > 0)
                {
                    attachmentCursor.enabled    = true;
                    attachmentTextOfPOI.enabled = true;

                    attachmentCursor.rectTransform.anchoredPosition =
                        attachmentImageInspector.rectTransform.anchoredPosition + curAttachment.pointsOfInterest[curAttachmentPointOfInterestIndex].posRelToImageCenter;

                    FlashAttachmentCursor();

                    if (attachmentPointDescriptionTextIsUnraveling)
                    {
                        if (Time.time - attachmentUnravelingTextRefTime > attachmentUnravelingTextTimePerCharForPOI)
                        {
                            if (curAttachmentPointDescriptionCharIndex < unravelingCharsForPOI.Count)
                            {
                                attachmentTextOfPOI.text += unravelingCharsForPOI[curAttachmentPointDescriptionCharIndex];
                                curAttachmentPointDescriptionCharIndex++;

                                attachmentUnravelingTextRefTime = Time.time;
                            }
                            else
                            {
                                attachmentPointDescriptionTextIsUnraveling = false;
                            }
                        }
                    }
                }
            }
            else
            {
                attachmentCursor.enabled    = false;
                attachmentTextOfPOI.enabled = false;
            }

            break;

        case MailMode.Closing:

            mailListBgd.texture = transitionScreenFrames[curtransitionScreenFramesIndex];

            if (Time.time - transitionScreenFrameRefTime > transitionScreenFrameTime)
            {
                if (curtransitionScreenFramesIndex > 0)
                {
                    curtransitionScreenFramesIndex--;
                    transitionScreenFrameRefTime = Time.time;
                }
                else
                {
                    ShowEMail(false);

                    MailState = MailMode.Inactive;
                }
            }

            break;
        }
    }
Esempio n. 8
0
        private void ParseNestedContent(string[] NestedCollectionLines, ref EMailBodyAlternateView[] Views, ref EMailAttachment[] Attachments)
        {
            string boundary = string.Empty;

            int[]    boundariesPos = null;
            string[] nestedContent = null;
            string   messageLine   = string.Empty;

            int    headerEndLine = FindHeaderEnd(NestedCollectionLines);
            string contentType   = ParseNestedContentHeaders(GetHeaderLines(NestedCollectionLines, headerEndLine), out boundary);

            if (boundary != null && boundary != string.Empty)
            {
                boundariesPos = FindBoundariesPositions(NestedCollectionLines, boundary, headerEndLine);
            }

            EMailBodyAlternateView[] parsedViews       = null;
            EMailAttachment[]        parsedAttachments = null;

            switch (contentType)
            {
            case "multipart/alternative":
                ParseMultipartAlternativeViews(GetBodyLines(NestedCollectionLines, headerEndLine), boundary, ref parsedViews, ref parsedAttachments);
                break;

            case "multipart/mixed":
            case "multipart/related":
                for (int i = 0; i < boundariesPos.Length - 1;)
                {
                    nestedContent = GetStringArrayPart(GetBodyLines(NestedCollectionLines, headerEndLine), boundariesPos[i], boundariesPos[++i]);
                    ParseNestedContent(nestedContent, ref Views, ref Attachments);
                }

                break;

            case "text/plain":
            case "text/html":
            case "text/htm":
            case "":
                parsedViews = new EMailBodyAlternateView[] { new EMailBodyAlternateView() };
                ParseAlternativeView(ref parsedViews[0], NestedCollectionLines);
                break;

            default:
                parsedAttachments = new EMailAttachment[] { new EMailAttachment() };
                ParseAttachment(ref parsedAttachments[0], NestedCollectionLines);
                break;
            }

            if (Views == null)
            {
                Views = new EMailBodyAlternateView[0];
            }
            if (Attachments == null)
            {
                Attachments = new EMailAttachment[0];
            }
            if (parsedViews == null)
            {
                parsedViews = new EMailBodyAlternateView[0];
            }
            if (parsedAttachments == null)
            {
                parsedAttachments = new EMailAttachment[0];
            }

            EMailBodyAlternateView[] newViewsCollection = new EMailBodyAlternateView[Views.Length + parsedViews.Length];
            Array.Copy(Views, newViewsCollection, Views.Length);
            Array.Copy(parsedViews, 0, newViewsCollection, Views.Length, parsedViews.Length);

            EMailAttachment[] newAttachmentsCollection = new EMailAttachment[Attachments.Length + parsedAttachments.Length];
            Array.Copy(Attachments, newAttachmentsCollection, Attachments.Length);
            Array.Copy(parsedAttachments, 0, newAttachmentsCollection, Attachments.Length, parsedAttachments.Length);

            Views       = newViewsCollection;
            Attachments = newAttachmentsCollection;

            return;
        }
Esempio n. 9
0
 private void ParseAttachmentContent(ref EMailAttachment Attachment, string[] AttachmentContentLines)
 {
     Attachment.ContentStream = ConcatenateStringArray(AttachmentContentLines);
 }
Esempio n. 10
0
        private void ParseAttachmentHeaders(ref EMailAttachment Attachment, string[] AttachmentHeaderLines)
        {
            Regex     validHeaderLineRegEx = new Regex(VALIDHEADERPATTERN);
            Match     validHeaderLineMatch;
            ArrayList linkedRes = new ArrayList();

            string[] fixedMessageHeaderLines = SplitMultiValueLines(AttachmentHeaderLines);
            bool     continuesFromPrevious   = false;
            string   lastHeaderProcessed     = string.Empty;
            string   headerName  = string.Empty;
            string   headerValue = string.Empty;

            foreach (string line in fixedMessageHeaderLines)
            {
                continuesFromPrevious = (line.StartsWith("\t") || line.StartsWith(" "));
                validHeaderLineMatch  = validHeaderLineRegEx.Match(line);

                if (validHeaderLineMatch.Groups.Count < 3)
                {
                    continue;
                }

                if (continuesFromPrevious && CheckValidDateString(line))
                {
                    headerName  = lastHeaderProcessed;
                    headerValue = line.Trim();
                }
                else
                {
                    headerName  = validHeaderLineMatch.Groups[1].Value.Trim().ToLower();
                    headerValue = validHeaderLineMatch.Groups[2].Value.Trim();
                }

                switch (headerName)
                {
                case "content-type":
                    Attachment.ContentType = GetCleanValue(headerValue);
                    break;

                case "content-transfer-encoding":
                    Attachment.ContentTransferEncoding = GetCleanValue(headerValue);
                    break;

                case "content-disposition":
                    Attachment.ContentDisposition = GetCleanValue(headerValue);
                    break;

                case "name-encoding":
                    Attachment.NameEncoding = GetCleanValue(headerValue);
                    break;

                case "ID":
                    Attachment.Id = GetCleanValue(headerValue);
                    break;

                case "content-description":
                    Attachment.ContentDescription = GetCleanValue(headerValue);
                    break;

                case "filename":
                    Attachment.FileName = GetCleanValue(headerValue);
                    break;

                case "name":
                    Attachment.Name = GetCleanValue(headerValue);
                    break;
                }
            }
        }
Esempio n. 11
0
        private void ParseMessageContent(ref EMailMessage OriginalEmail, string[] MessageContentLines, int[] BoundariesPos)
        {
            int bodyAttachsCount = 0;
            EMailBodyAlternateView refBody;

            string[] bodyLines;

            EMailBodyAlternateView[] views   = null;
            EMailAttachment[]        attachs = null;

            switch (OriginalEmail.ContentType.ToLower())
            {
            case null:
                OriginalEmail.ContentType = "text/plain";
                goto case "text/plain";

            case "text":
                OriginalEmail.ContentType = "text/plain";
                goto case "text/plain";

            case "text/plain":
            case "text/html":
            case "text/htm":
            case "":
                OriginalEmail.Body = new EMailBodyAlternateView();
                refBody            = OriginalEmail.Body;

                refBody.ContentTransferEncoding = OriginalEmail.ContentTransferEncoding;
                refBody.ContentType             = OriginalEmail.ContentType;

                string messageLine;
                if (OriginalEmail.ContentTransferEncoding == "base64")
                {
                    messageLine = ConcatenateStringArray(GetStringArrayPart(MessageContentLines, 0, MessageContentLines.Length - 1), true);
                }
                else
                {
                    messageLine = ConcatenateStringArray(MessageContentLines);
                }

                refBody.ContentStream = messageLine;
                break;

            case "multipart/alternative":
                ParseMultipartAlternativeViews(MessageContentLines, BoundariesPos, ref views, ref attachs);
                OriginalEmail.Body = views[0];
                if (views != null && views.Length > 1)
                {
                    OriginalEmail.Views = new EMailBodyAlternateView[views.Length - 1];
                    EMailBodyAlternateView[] viewsRef = OriginalEmail.Views;
                    Array.Copy(views, 1, viewsRef, 0, views.Length - 1);
                }
                OriginalEmail.Attachments = attachs;
                break;

            case "multipart/mixed":
            case "multipart/related":
            case "multipart/report":
                if (BoundariesPos.Length > 2)
                {
                    bodyLines        = GetStringArrayPart(MessageContentLines, BoundariesPos[0], BoundariesPos[1]);
                    bodyAttachsCount = BoundariesPos.Length - 2;
                }
                else
                {
                    bodyLines = GetStringArrayPart(MessageContentLines, BoundariesPos[0], BoundariesPos[1]);
                }
                ParseNestedContent(bodyLines, ref views, ref attachs);
                OriginalEmail.Body        = views[0];
                OriginalEmail.Attachments = attachs;
                if (views != null && views.Length > 1)
                {
                    OriginalEmail.Views = new EMailBodyAlternateView[views.Length - 1];
                    EMailBodyAlternateView[] viewsRef = OriginalEmail.Views;
                    Array.Copy(views, 1, viewsRef, 0, views.Length - 1);
                }
                break;
            }

            if (bodyAttachsCount > 0)
            {
                int inlineAttachs = OriginalEmail.Attachments.Length;

                EMailAttachment[] emAttachments = new EMailAttachment[inlineAttachs + bodyAttachsCount];
                Array.Copy(OriginalEmail.Attachments, emAttachments, inlineAttachs);

                OriginalEmail.Attachments = emAttachments;

                for (int i = inlineAttachs, j = 0; i < inlineAttachs + bodyAttachsCount; ++i, j++)
                {
                    OriginalEmail.Attachments[i] = new EMailAttachment();

                    int startLine = BoundariesPos[1 + j];
                    int endLine   = BoundariesPos[2 + j];

                    ParseAttachment(ref OriginalEmail.Attachments[i], GetStringArrayPart(MessageContentLines, startLine + 1, endLine - 1));
                }
            }
        }