/// <summary>
        /// メールのアドレスから宛先情報を検索する
        /// </summary>
        /// <param name="addressList">メールのTO, CC, BCC</param>
        /// <returns> 検索した宛先情報のリスト</returns>
        public List <RecipientInformationDto> SearchContact(List <Recipient> recipientsList, Utility.OutlookItemType itemType)
        {
            /// 検索結果の宛先情報のリスト
            List <RecipientInformationDto> _recipientInformationList = new List <RecipientInformationDto>();

            /// ファクトリオブジェクトに連絡先クラスのインスタンスの生成をしてもらう
            ContactFactory  contactFactory = new ContactFactory();
            List <IContact> contactList    = contactFactory.CreateContacts();

            /// ある1人の受信者の宛先情報を取得する
            foreach (var recipient in recipientsList)
            {
                RecipientInformationDto recipientInformation = null;

                try
                {
                    /// それぞれの連絡先クラスで検索する
                    foreach (var item in contactList)
                    {
                        ContactItem contactItem = item.getContactItem(recipient);

                        /// 送信先アドレスからその人の情報が見つかれば、名、部署、会社名、タイプをDtoにセット
                        if (contactItem != null)
                        {
                            string jobTitle = Utility.FormatJobTitle(contactItem.JobTitle);

                            // TaskRequstResponseは強制的にToにする
                            OlMailRecipientType recipientType = itemType != Utility.OutlookItemType.TaskRequestResponse ?
                                                                (OlMailRecipientType)recipient.Type :
                                                                OlMailRecipientType.olTo;

                            recipientInformation = new RecipientInformationDto(contactItem.FullName, contactItem.Department, contactItem.CompanyName, jobTitle, recipientType);
                            break;
                        }
                    }

                    if (recipientInformation == null)
                    {
                        recipientInformation = new RecipientInformationDto(
                            Utility.GetDisplayNameAndAddress(recipient),
                            (OlMailRecipientType)recipient.Type);
                    }
                    _recipientInformationList.Add(recipientInformation);
                }
                /// 例外が発生した場合、Nameを表示する
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.Message);

                    _recipientInformationList.Add(new RecipientInformationDto(
                                                      Utility.GetDisplayNameAndAddress(recipient),
                                                      (OlMailRecipientType)recipient.Type));
                }
            }

            return(_recipientInformationList);
        }
예제 #2
0
        /// <summary>
        ///  アイテム送信時の宛先表示画面を生成する
        /// </summary>
        /// <param name="item">アイテム</param>
        /// <param name="cancel">送信をしないかどうか</param>
        private void ConfirmContact(object Item, ref bool Cancel)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                // アイテムタイプをMailで初期化
                Utility.OutlookItemType itemType = Utility.OutlookItemType.Mail;

                // アイテムの宛先を取得
                List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>();
                recipientsList = Utility.GetRecipients(Item, ref itemType, true);

                // 会議の招待に対する返事の場合、宛先表示しない
                if (itemType == Utility.OutlookItemType.MeetingResponse ||
                    recipientsList == null)
                {
                    return;
                }

                // 宛先情報のリストを取得
                SearchRecipient searchRecipient = new SearchRecipient();
                List <RecipientInformationDto> recipientList = searchRecipient.SearchContact(recipientsList, itemType);

                // 送信者のExchangeUserオブジェクトを取得
                RecipientInformationDto senderInformation = null;
                senderInformation = Utility.GetSenderInfomation(Item);

                // 受信者の宛先情報のリストに、送信者の情報も追加する
                if (senderInformation != null)
                {
                    recipientList.Add(senderInformation);
                }

                Cursor.Current = Cursors.Default;

                // 引数に宛先情報を渡し、宛先表示画面を表示する
                RecipientConfirmationWindow recipientWindow = new RecipientConfirmationWindow(itemType, recipientList);
                DialogResult result = recipientWindow.ShowDialog();

                // 画面でOK以外が選択された場合
                if (result != DialogResult.OK)
                {
                    // メール送信のイベントをキャンセルする
                    Cancel = true;
                }
            }
            /// 例外が発生した場合、エラーダイアログを表示
            /// 送信イベントをキャンセルする
            catch (Exception ex)
            {
                // エラーダイアログの呼び出し
                ErrorDialog.ShowException(ex);

                Cancel = true;
            }
        }
예제 #3
0
        /// <summary>
        /// SharingItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">SharingItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.SharingItem item)
        {
            if (item.SenderEmailAddress == null)
            {
                return(GetCurrentUserInformation());
            }

            Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient(item.SenderEmailAddress);

            Outlook.AddressEntry addressEntry = null;
            Outlook.ExchangeUser exchUser     = null;
            if (recipient != null)
            {
                addressEntry = recipient.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // ExchangeUserが取得できないが、送信者情報は取得できた場合
            else
            {
                string displayName;
                if (item.SenderName != null && !Utility.IsEmailAddress(item.SenderName))
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }
                else if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
예제 #4
0
        /// <summary>
        /// AppointmentItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">AppointmentItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.AppointmentItem item)
        {
            // 先頭(Recipients[1])のRecipientは送信者なので、送信者のExchangeUserを取得
            Outlook.Recipient    recipient    = item.Recipients[1];
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            Outlook.ExchangeUser exchUser     = getExchangeUser(addressEntry);
            if (exchUser == null)
            {
                // 起動されたOutlookのユーザを送信者として取得
                addressEntry = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            else
            {
                string displayName;
                if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(recipient.Name, recipient.Address);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }

            return(senderInformation);
        }
예제 #5
0
        /// <summary>
        /// 自分自身の送信者情報(Dto)を取得する
        /// </summary>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetCurrentUserInformation()
        {
            Outlook.Recipient    recipient    = Globals.ThisAddIn.Application.Session.CurrentUser;
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            Outlook.ExchangeUser exchUser     = getExchangeUser(addressEntry);

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にない場合
            else
            {
                string displayName;
                if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else if (recipient != null)
                {
                    displayName = recipient.Name;
                }
                else
                {
                    displayName = "※取得できませんでした";
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
예제 #6
0
        /// <summary>
        /// 送信者、To、Cc、Bccを取得と検索し、宛先リスト画面を呼び出す
        /// </summary>
        private void ShowRecipientListWindow(object activeItem)
        {
            Cursor.Current = Cursors.WaitCursor;

            /// Mailで初期化
            Utility.OutlookItemType itemType          = Utility.OutlookItemType.Mail;
            RecipientInformationDto senderInformation = null;

            /// メールの宛先を取得
            List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>();

            recipientsList = Utility.GetRecipients(activeItem, ref itemType);

            ///  会議招集の返信の場合、そのまま送信する
            if (recipientsList == null)
            {
                return;
            }

            /// 検索し、受信者の宛先情報リストが戻ってくる
            SearchRecipient searchRecipient = new SearchRecipient();
            List <RecipientInformationDto> recipientList = searchRecipient.SearchContact(recipientsList, itemType);

            /// 送信者のExchangeUserオブジェクトを取得
            senderInformation = Utility.GetSenderInfomation(activeItem);

            /// 受信者の宛先情報のリストに、送信者の情報も追加する
            if (senderInformation != null)
            {
                recipientList.Add(senderInformation);
            }

            Cursor.Current = Cursors.Default;

            // 宛先リストの画面を表示する
            RecipientListWindow recipientListWindow = new RecipientListWindow(itemType, recipientList);

            recipientListWindow.ShowDialog();
        }
예제 #7
0
        /// <summary>
        /// TaskRequestItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">TaskRequestItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.TaskRequestItem item)
        {
            Outlook.Recipient   recipient;
            Outlook.ContactItem contactItem;
            if (IsSendTaskRequest(item.GetAssociatedTask(false)))
            {
                //これから送信するTaskRequestItem
                recipient   = Globals.ThisAddIn.Application.Session.CurrentUser;
                contactItem = null;
            }
            else
            {
                //受信したTaskRequestItem
                Outlook.TaskItem task = item.GetAssociatedTask(false);
                recipient = task.Recipients[1];
                try
                {
                    contactItem = recipient.AddressEntry.GetContact();
                }
                catch
                {
                    contactItem = null;
                }
            }
            Outlook.AddressEntry addressEntry = recipient.AddressEntry;
            Outlook.ExchangeUser exchUser     = getExchangeUser(addressEntry);

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にないが、「連絡先」にいる場合
            else if (contactItem != null)
            {
                senderInformation = new RecipientInformationDto(contactItem.FullName,
                                                                contactItem.Department,
                                                                contactItem.CompanyName,
                                                                FormatJobTitle(contactItem.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にも「連絡先」にもない場合
            else
            {
                string displayName;
                if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else if (recipient != null)
                {
                    displayName = recipient.Name;
                }
                else
                {
                    displayName = "※取得できませんでした"; //TODO:メールヘッダーのFromから取得する
                }
                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
예제 #8
0
        /// <summary>
        /// ReportItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">ReportItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.ReportItem item)
        {
            RecipientInformationDto senderInformation = new RecipientInformationDto("Microsoft Outlook", Outlook.OlMailRecipientType.olOriginator);

            return(senderInformation);
        }
예제 #9
0
        /// <summary>
        /// MeetingItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">MeetingItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.MeetingItem item)
        {
            // SenderEmailAddressから、送信者のAddressEntry及びExchangeUserを取得
            Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient(item.SenderEmailAddress);

            Outlook.AddressEntry addressEntry = null;
            Outlook.ExchangeUser exchUser     = null;
            Outlook.ContactItem  contactItem  = null;
            if (recipient != null)
            {
                addressEntry = recipient.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
                try
                {
                    contactItem = addressEntry.GetContact();
                }
                catch
                {
                    contactItem = null;
                }
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にないが、「連絡先」にいる場合
            else if (contactItem != null)
            {
                senderInformation = new RecipientInformationDto(contactItem.FullName,
                                                                contactItem.Department,
                                                                contactItem.CompanyName,
                                                                FormatJobTitle(contactItem.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にも「連絡先」にもない場合
            else
            {
                string displayName;
                if (item.SenderName != null && !Utility.IsEmailAddress(item.SenderName))
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }
                else if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }
            return(senderInformation);
        }
예제 #10
0
        /// <summary>
        /// MailItemの送信者情報(Dto)を取得する
        /// </summary>
        /// <param name="Item">MailItemオブジェクト</param>
        /// <returns>送信者の宛先情報DTO(送信者が取得できない場合null)</returns>
        private static RecipientInformationDto GetSenderInformation(Outlook.MailItem item)
        {
            Outlook.AddressEntry addressEntry;
            Outlook.ExchangeUser exchUser;
            Outlook.Recipient    recipient;
            Outlook.ContactItem  contactItem;

            //Office365(Exchangeユーザー)からのメール
            if (item.Sender != null)
            {
                addressEntry = item.Sender;
                recipient    = Globals.ThisAddIn.Application.Session.CreateRecipient(addressEntry.Address);
                exchUser     = getExchangeUser(recipient.AddressEntry);
            }
            //送信元メールアドレスが取れた場合
            else if (item.SenderEmailAddress != null)
            {
                recipient    = Globals.ThisAddIn.Application.Session.CreateRecipient(item.SenderEmailAddress);
                addressEntry = recipient.AddressEntry;
                exchUser     = getExchangeUser(recipient.AddressEntry);
            }
            //新規にメール作成中の場合ここ
            else
            {
                // 起動されたOutlookのユーザを送信者として取得
                recipient    = Globals.ThisAddIn.Application.Session.CurrentUser;
                addressEntry = recipient.AddressEntry;
                exchUser     = getExchangeUser(addressEntry);
            }

            //個人の「連絡先」に登録されているかもしれない
            contactItem = null;
            if (addressEntry != null)
            {
                try
                {
                    contactItem = addressEntry.GetContact();
                }
                catch
                {
                    contactItem = null;
                }
            }

            RecipientInformationDto senderInformation = null;

            // 送信者のExchangeUserが取得できた場合
            if (exchUser != null)
            {
                senderInformation = new RecipientInformationDto(exchUser.Name,
                                                                exchUser.Department,
                                                                exchUser.CompanyName,
                                                                FormatJobTitle(exchUser.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にないが、「連絡先」にいる場合
            else if (contactItem != null)
            {
                senderInformation = new RecipientInformationDto(contactItem.FullName,
                                                                contactItem.Department,
                                                                contactItem.CompanyName,
                                                                FormatJobTitle(contactItem.JobTitle),
                                                                Outlook.OlMailRecipientType.olOriginator);
            }
            // Exchangeアドレス帳にも「連絡先」にもない場合
            else
            {
                string displayName;
                if (item.SenderName != null && !Utility.IsEmailAddress(item.SenderName))
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }
                else if (recipient != null && !Utility.IsEmailAddress(recipient.Name))
                {
                    displayName = GetDisplayNameAndAddress(recipient);
                }
                else if (addressEntry != null)
                {
                    displayName = FormatDisplayNameAndAddress(addressEntry.Name, addressEntry.Address);
                }
                else
                {
                    displayName = FormatDisplayNameAndAddress(item.SenderName, item.SenderEmailAddress);
                }

                senderInformation = new RecipientInformationDto(displayName, Outlook.OlMailRecipientType.olOriginator);
            }

            return(senderInformation);
        }