Пример #1
0
        public List <NovellGroupWiseMail> OpenFolder(Folder folder)
        {
            String date;
            String str;

            WebReference.createCursorRequest   creq = new WebReference.createCursorRequest();
            WebReference.createCursorResponse  cresp;
            WebReference.destroyCursorRequest  dreq = new WebReference.destroyCursorRequest();
            WebReference.destroyCursorResponse dres;
            WebReference.readCursorRequest     rreq = new WebReference.readCursorRequest();
            WebReference.readCursorResponse    rresp;
            WebReference.Mail item;

            creq.container = folder.id;
            creq.view      = null;
            cresp          = ws.createCursorRequest(creq);

            if (0 != cresp.status.code)
            {
                throw new NovellGroupWiseException(String.Format("Can not open Group Wise {0}", folder.name));
            }

            string letters = "";
            List <NovellGroupWiseMail> mails = new List <NovellGroupWiseMail>();

            for (;;)
            {
                rreq.container = folder.id;
                rreq.count     = 100;
                rreq.cursor    = cresp.cursor;
                rresp          = ws.readCursorRequest(rreq);
                if (0 != rresp.status.code || null == rresp.items ||
                    null == rresp.items.item)
                {
                    break;
                }
                for (int i = 0; i < rresp.items.item.Length; i++)
                {
                    item = (WebReference.Mail)rresp.items.item[i];
                    //учитываем только письма, остальное не интересно
                    //что бывает остальное - смотрим в Samples
                    //  if (item is WebReference.Mail || item is WebReference.PhoneMessage)
                    if (item is WebReference.Mail)
                    {
                        NovellGroupWiseMail mail = new NovellGroupWiseMail();
                        mail.Id = item.id;
                        //дата доставки письма
                        mail.DateDelivered = item.delivered;

                        //прочитано пользователем
                        if (null != item.status && item.status.read)
                        {
                            mail.Read = true;
                        }
                        if (null != item.distribution && null != item.distribution.from && null != item.distribution.from.displayName)
                        {
                            //от кого
                            mail.From      = item.distribution.from.displayName;
                            mail.FromEmail = item.distribution.from.email;

                            //кому
                            mail.To = item.distribution.to;

                            if (item.distribution.recipients != null)
                            {
                                mail.Recipients = new List <GroupWiseMailRecipient>();
                                foreach (var recipient in item.distribution.recipients)
                                {
                                    GroupWiseMailRecipient rec = new GroupWiseMailRecipient()
                                    {
                                        Id    = recipient.uuid,
                                        Email = recipient.email,
                                        Name  = recipient.displayName
                                    };
                                    mail.Recipients.Add(rec);
                                }
                            }
                        }
                        //тема письма
                        mail.Subject = item.subject;

                        //id письма
                        mail.Id = item.id;

                        mails.Add(mail);
                    }
                }
                //не более чем 100, кстати почему?
                if (100 != rresp.items.item.Length)
                {
                    break;
                }
            }
            //удаляем курсор (черная магия)
            dreq.container = folder.id;
            dreq.cursor    = cresp.cursor;
            dres           = ws.destroyCursorRequest(dreq);
            return(mails);
        }
Пример #2
0
        public NovellGroupWiseMail ReadMail(string id)
        {
            WebReference.Mail            item;
            WebReference.getItemRequest  req = new WebReference.getItemRequest();
            WebReference.getItemResponse resp;
            NovellGroupWiseMail          mail = new NovellGroupWiseMail();

            req.id   = id;
            req.view = "default message peek attachments recipientStatus";
            resp     = ws.getItemRequest(req);

            if (0 == resp.status.code)
            {
                item = (WebReference.Mail)resp.item;
                if (item is WebReference.Mail)
                {
                    String str = item.GetType().ToString();
                    int    i   = str.LastIndexOf('.');
                    if (-1 != i)
                    {
                        str = str.Substring(i + 1);
                    }

                    mail.Recipients = new List <GroupWiseMailRecipient>();
                    Recipient[] rec = item.distribution.recipients;
                    for (int j = 0; j < rec.Count(); j++)
                    {
                        GroupWiseMailRecipient recipient = new GroupWiseMailRecipient
                        {
                            Id               = rec[j].uuid,
                            Email            = rec[j].email,
                            DistributionType = rec[j].distType.ToString(),
                            Name             = rec[j].displayName
                        };
                        mail.Recipients.Add(recipient);
                    }


                    mail.To = item.distribution.to;
                    mail.BC = item.distribution.bc;
                    mail.CC = item.distribution.cc;



                    String Text = str;
                    mail.HasAttachments = item.hasAttachment;
                    if (null != item.distribution && null != item.distribution.from &&
                        null != item.distribution.from.displayName)
                    {
                        mail.From = item.distribution.from.displayName;
                    }
                    if (null != item.distribution.to)
                    {
                        mail.To = item.distribution.to;
                    }
                    if (null != item.subject)
                    {
                        mail.Subject = item.subject;
                    }
                    if (null != item.message && 0 != item.message.Length)
                    {
                        WebReference.MessagePart part = (WebReference.MessagePart)item.message.GetValue(0);
                        System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();
                        mail.Text = utf8.GetString(part.Value);
                    }
                    //   if (mail.HasAttachments)
                    //    {
                    WebReference.AttachmentItemInfo info;
                    List <string> attachmentsArray = new List <string>();
                    if (item.attachments != null)
                    {
                        for (i = 0; i < item.attachments.Length; i++)
                        {
                            info = (WebReference.AttachmentItemInfo)item.attachments.GetValue(i);
                            if (null == info || info.id.itemReference)
                            {
                                continue;
                            }
                            string fileName = exportData(info);
                            if (info.name.ToLower() == "text.htm")
                            {
                                mail.HtmlText = File.ReadAllText(HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "//" + fileName);
                            }
                            else //if (info.name.ToLower() != "mime.822")
                            {
                                attachmentsArray.Add(fileName);
                            }
                        }
                        mail.Attachments = attachmentsArray;
                    }
                    //  }
                }
            }

            return(mail);
        }
Пример #3
0
        /// <summary>
        /// Attachment should be with ABSOLUTE PATH (with AppPath())
        /// </summary
        public void SendEmail(NovellGroupWiseMail mail)
        {
            WebReference.Mail             mailToSend = new WebReference.Mail();
            WebReference.MessagePart[]    part;
            WebReference.NameAndEmail     item;
            WebReference.Recipient[]      recips;
            WebReference.sendItemRequest  req;
            WebReference.sendItemResponse resp;
            mailToSend.subject = mail.Subject;

            var att = new WebReference.AttachmentItemInfo();

            List <AttachmentItemInfo> atts = new List <AttachmentItemInfo>();



            //сохранить html text в файл text.htm
            if (mail.HtmlText != null)
            {
                String path = HttpContext.Current.Server.MapPath("~/TemporaryFiles/") + Guid.NewGuid() + ".htm";
                var    fs   = new FileStream(path, FileMode.Create);
                using (var bw = new BinaryWriter(fs))
                {
                    bw.Write(mail.HtmlText);
                }
                fs.Close();

                var fss = new FileStream(path, FileMode.OpenOrCreate);
                using (var binaryReader = new BinaryReader(fss))
                {
                    att.data = binaryReader.ReadBytes((int)fss.Length);
                }
                fss.Close();
                att.name = "text.htm";
                atts.Add(att);
            }


            if (mail.Attachments != null)
            {
                foreach (var attachment in mail.Attachments)
                {
                    var fs = new FileStream(attachment, FileMode.OpenOrCreate);
                    using (var binaryReader = new BinaryReader(fs))
                    {
                        att.data = binaryReader.ReadBytes((int)fs.Length);
                    }
                    att.name = System.IO.Path.GetFileName(attachment);
                    atts.Add(att);
                    fs.Close();
                }
            }

            mailToSend.attachments   = atts.ToArray();
            mailToSend.hasAttachment = true;

            //if (0 != mail.Text.Length)
            //{
            //    part = new WebReference.MessagePart[1];
            //    part[0] = new WebReference.MessagePart();
            //    part[0].Value = System.Text.UTF8Encoding.UTF8.GetBytes(mail.Text);
            //    mailToSend.message = part;
            //}

            recips = new WebReference.Recipient[mail.Recipients.Count];
            for (int i = 0; i < mail.Recipients.Count; i++)
            {
                recips[i]             = new WebReference.Recipient();
                recips[i].displayName = mail.Recipients[i].Name;
                recips[i].email       = mail.Recipients[i].Email;
                recips[i].uuid        = mail.Recipients[i].Id;
            }

            mailToSend.distribution            = new WebReference.Distribution();
            mailToSend.distribution.recipients = recips;

            req      = new WebReference.sendItemRequest();
            req.item = mailToSend;

            resp = ws.sendItemRequest(req);
        }