Esempio n. 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);
        }
Esempio n. 2
0
        public List <NovellGroupWiseContact> GetContacts(String bookId)
        {
            String cont;
            String email;
            String name;
            String str;
            String uuid;

            WebReference.AddressBookItem       item;
            WebReference.Contact               contact;
            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;
            cont = bookId;
            List <NovellGroupWiseContact> contacts = new List <NovellGroupWiseContact>();

            creq.container = cont;
            cresp          = ws.createCursorRequest(creq);
            if (0 != cresp.status.code)
            {
                throw new NovellGroupWiseException("Cannot connect to Novell Group Wise AddressBookCollection");
            }
            for (;;)
            {
                rreq.container = cont;
                rreq.count     = 100;
                rreq.cursor    = cresp.cursor;
                try
                {
                    rresp = ws.readCursorRequest(rreq);
                }
                catch (InvalidOperationException ex)
                {
                    System.Console.WriteLine(ex);
                    continue;
                }
                if (0 != rresp.status.code)
                {
                    break;
                }
                for (int i = 0; null != rresp.items && null != rresp.items.item && i < rresp.items.item.Length; i++)
                {
                    NovellGroupWiseContact novellContact = new NovellGroupWiseContact();
                    item = (WebReference.AddressBookItem)rresp.items.item[i];
                    name = item.name;
                    novellContact.Name = item.name;
                    email = null;
                    uuid  = item.uuid;
                    novellContact.UUId = item.uuid;
                    if (item is WebReference.Contact)
                    {
                        contact            = (WebReference.Contact)item;
                        str                = "C";
                        novellContact.TYpe = "Contact";
                        if (null != contact.emailList && null != contact.emailList.primary)
                        {
                            novellContact.Email = contact.emailList.primary;
                        }
                        if (null == name || 0 == name.Length)
                        {
                            if (null != contact.fullName.firstName)
                            {
                                novellContact.FirstName = contact.fullName.firstName;
                                novellContact.Name      = contact.fullName.firstName;

                                if (null != contact.fullName.lastName)
                                {
                                    novellContact.Name    += " ";
                                    novellContact.Name    += contact.fullName.lastName;
                                    novellContact.LastNAme = contact.fullName.lastName;
                                }
                            }
                            else if (null != contact.fullName.lastName)
                            {
                                novellContact.Name     = contact.fullName.lastName;
                                novellContact.LastNAme = contact.fullName.lastName;
                            }
                            else
                            {
                                novellContact.Name     = contact.fullName.displayName;
                                novellContact.LastNAme = contact.fullName.displayName;
                            }
                        }
                    }
                    else if (item is WebReference.Resource)
                    {
                        novellContact.TYpe  = "Resource";
                        novellContact.Email = ((WebReference.Resource)item).email;
                    }
                    else if (item is WebReference.Group)
                    {
                        novellContact.TYpe = "Group";
                    }
                    else if (item is WebReference.Organization)
                    {
                        novellContact.TYpe  = "Organization";
                        novellContact.Email = ((WebReference.Organization)item).website;
                    }
                    else
                    {
                        str = "U";
                        novellContact.TYpe = "Unknown";
                    }
                    contacts.Add(novellContact);
                }
                if (null == rresp.items || null == rresp.items.item || 100 != rresp.items.item.Length)
                {
                    break;
                }
            }
            dreq.container = cont;
            dreq.cursor    = cresp.cursor;
            dres           = ws.destroyCursorRequest(dreq);
            return(contacts);
        }