private void ProcessTaskRequestItem(ref bool cancel, Outlook.TaskRequestItem item) { Debug.WriteLine("ProcessTaskRequestItem: Outlook.TaskRequestItem found"); Debug.WriteLine("=============================================================================="); // TODO: Treat tasks the same as Meetings }
/// <summary> /// 送信者の情報(Dto)を取得する /// </summary> /// <param name="Item">Outlookアイテムオブジェクト</param> /// <returns>送信者の宛先情報インスタンス(送信者が取得できない場合null)</returns> public static RecipientInformationDto GetSenderInfomation(object Item) { if (Item is Outlook.MailItem) { Outlook.MailItem mail = (Item as Outlook.MailItem); return(GetSenderInformation(mail)); } else if (Item is Outlook.MeetingItem) { Outlook.MeetingItem meeting = Item as Outlook.MeetingItem; return(GetSenderInformation(meeting)); } else if (Item is Outlook.AppointmentItem) { Outlook.AppointmentItem appointment = Item as Outlook.AppointmentItem; return(GetSenderInformation(appointment)); } else if (Item is Outlook.ReportItem) { Outlook.ReportItem report = Item as Outlook.ReportItem; return(GetSenderInformation(report)); } else if (Item is Outlook.SharingItem) { Outlook.SharingItem sharing = Item as Outlook.SharingItem; return(GetSenderInformation(sharing)); } else if (Item is Outlook.TaskItem) { Outlook.TaskItem task = Item as Outlook.TaskItem; return(GetSenderInformation(task)); } else if (Item is Outlook.TaskRequestItem) { Outlook.TaskRequestItem taskRequest = Item as Outlook.TaskRequestItem; return(GetSenderInformation(taskRequest)); } else if (Item is Outlook.TaskRequestAcceptItem) { Outlook.TaskRequestAcceptItem taskRequestAcceptItem = Item as Outlook.TaskRequestAcceptItem; string mailHeader = GetMailHeader(taskRequestAcceptItem.PropertyAccessor); return(GetSenderInformationFromMailHeader(mailHeader)); } else if (Item is Outlook.TaskRequestDeclineItem) { Outlook.TaskRequestDeclineItem taskRequestDeclineItem = Item as Outlook.TaskRequestDeclineItem; string mailHeader = GetMailHeader(taskRequestDeclineItem.PropertyAccessor); return(GetSenderInformationFromMailHeader(mailHeader)); } else { throw new NotSupportedException("未対応のOutook機能です。"); } }
/// <summary> /// TaskRequestItemから、宛先(Recipient)のリスト取得する /// </summary> /// <param name="Item">TaskRequestItemオブジェクト</param> /// <returns>List<Outlook.Recipient></returns> private static List <Outlook.Recipient> GetRecipientList(Outlook.TaskRequestItem item) { Outlook.TaskItem task = item.GetAssociatedTask(false); Outlook.Recipients recipients = task.Recipients; List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>(); if (recipients.Count == 0) { //ReportItemのままだと送信先が取れないため、 //いったんIPM.Noteとして別名保存⇒ロードしてからRecipientsを取得する Outlook.TaskRequestItem copiedItem = item.Copy(); copiedItem.MessageClass = "IPM.Note"; copiedItem.Save(); //IPM.Noteとして保存してからロードするとMailItemとして扱えるようになる var newReportItem = Globals.ThisAddIn.Application.Session.GetItemFromID(copiedItem.EntryID); Outlook.MailItem newMailItem = newReportItem as Outlook.MailItem; recipientsList = GetRecipientList(newMailItem); copiedItem.Delete(); return(recipientsList); } if (IsSendTaskRequest(task)) { //これから送信するTaskRequestItem for (int i = 1; i <= recipients.Count; i++) { recipientsList.Add(recipients[i]); } } else { //受信したTaskRequestItem Outlook.Recipient ownerRecipient = Globals.ThisAddIn.Application.Session.CreateRecipient(task.Owner); recipientsList.Add(ownerRecipient); } return(recipientsList); }
/// <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); }