private void BtnClearInvitation_Click(object sender, Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs e) { Func<string, bool> f = s => s.StartsWith("Accepted: ") || s.StartsWith("Declined: ") || s.StartsWith("Tentatively Accepted: "); InvitationsCounter = 0; Outlook.MAPIFolder inbox = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); for (int i = inbox.Items.Count; i > 0; i--) //foreach (var item in inbox.Items) { var item = inbox.Items[i]; Outlook.MailItem mail = item as Outlook.MailItem; if (mail != null && mail.Subject != null) { //todo: move it to configuration if (f(mail.Subject)) { mail.Delete(); InvitationsCounter++; } } Outlook.MeetingItem meeting = item as Outlook.MeetingItem; if (meeting != null) { if (f(meeting.ConversationTopic)) { meeting.Delete(); InvitationsCounter++; } } } }
public OutlookItem(object Item) { m_mail = Item as Outlook.MailItem; m_meeting = Item as Outlook.MeetingItem; IsSupportedItem = m_mail != null || m_meeting != null; }
private static ProtectiveMarking GetUserSelectedMarking(Outlook.MeetingItem item) { Debug.WriteLine("PspfMarkingsAddIn: GetUserSelectedMarking"); Debug.WriteLine("=============================================================================="); Outlook.UserProperties userProperties = null; Outlook.UserProperty userProperty = null; try { userProperties = item.UserProperties; userProperty = userProperties[TemporaryLabelPropertyName]; if (userProperty != null) { return(Config.Current.ProtectiveMarkings[userProperty.Value]); } } finally { if (userProperty != null) { Marshal.ReleaseComObject(userProperty); } if (userProperties != null) { Marshal.ReleaseComObject(userProperties); } } return(null); }
public FormTag(Outlook.MeetingItem meeting, bool defaultArchive = true) { InitializeComponent(); cbArchive.Checked = defaultArchive; _meeting = meeting; setup(meeting.Categories); }
private static void InsertPspfBodyHeader(Outlook.MeetingItem item, ProtectiveMarking marking) { Outlook.Inspector inspector = null; dynamic wordEditor = null; try { inspector = item.GetInspector; wordEditor = inspector.WordEditor; AddMarkingHeaderToDocument(marking, wordEditor); // Other methods seen to force the edits to persist: //item.Display(); //inspector.Activate(); causes the meeting to pop out a new window and stay open } finally { if (wordEditor != null) { Marshal.ReleaseComObject(wordEditor); } if (inspector != null) { Marshal.ReleaseComObject(inspector); } } }
/************************************************************************ * Name: : AfterSendingItem * Description : Occurs after sending an item ************************************************************************/ private void AfterSendingItem(object item) { bool sent = false; // 4 items that contains send action if (item is Outlook.MailItem) { Outlook.MailItem mailItem = (Outlook.MailItem)item; sent = mailItem.Sent; } else if (item is Outlook.MeetingItem) { Outlook.MeetingItem meetingItem = (Outlook.MeetingItem)item; sent = meetingItem.Sent; } else if (item is Outlook.MobileItem) { Outlook.MobileItem mobileItem = (Outlook.MobileItem)item; sent = mobileItem.Sent; } else if (item is Outlook.SharingItem) { Outlook.SharingItem sharingItem = (Outlook.SharingItem)item; sent = sharingItem.Sent; } //TODO: }
public UpdateMeetingAcceptancesAction( AppointmentSyncing synchroniser, Outlook.MeetingItem meeting) : base(5) { this.synchroniser = synchroniser; this.meeting = meeting; }
private static string GetHeader(Outlook.MeetingItem item, string headerName) { Outlook.PropertyAccessor accessor = null; try { accessor = item.PropertyAccessor; return(accessor.GetProperty(headerName)); } catch (System.Runtime.InteropServices.COMException) { Debug.WriteLine("GetHeader: Failed to retreive header, this is expected behaviour when the header is not present"); } catch (System.Exception ex) { Debug.WriteLine("GetHeader: Unexpected error retrieving header: " + ex.ToString()); } finally { if (accessor != null) { Marshal.ReleaseComObject(accessor); } } return(null); }
/// <summary>Handles the onAction event of the OpenMessage button. /// </summary> /// <param name="control">The source control of the event.</param> public void OpenMessage(Office.IRibbonControl control) { if (!string.IsNullOrWhiteSpace(currentSearchText)) { // Obtain a reference to selection. Outlook.Selection selection = ActiveExplorer.Selection; if (selection.Count == 0) { return; } // Open the first item that is a supported Outlook item. // The selection may contain various item types. IEnumerator e = ActiveExplorer.Selection.GetEnumerator(); while (e.MoveNext()) { if (e.Current is Outlook.MailItem) { Outlook.MailItem item = e.Current as Outlook.MailItem; item.Display(); FindInInspector(item.GetInspector, currentSearchText); break; } else if (e.Current is Outlook.MeetingItem) { Outlook.MeetingItem item = e.Current as Outlook.MeetingItem; item.Display(); FindInInspector(item.GetInspector, currentSearchText); break; } } } }
public void Tagger() { // If not a single mail or meeting is selection, the Tagger box won't open if (this.Application.ActiveExplorer().Selection.Count != 1) { return; } object selObject = this.Application.ActiveExplorer().Selection[1]; // If the selected Item is a MailItem, open the Tagger Box, and check 'Archive' by default. if (selObject is Outlook.MailItem) { Outlook.MailItem mail = selObject as Outlook.MailItem; System.Windows.Forms.Form f = new FormTag(mail, true); f.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; f.ShowDialog(); } // If the selected Item is a MeetingItem, open the Tagger Box, and don't check 'Archive' by default. else if (selObject is Outlook.MeetingItem) { Outlook.MeetingItem meeting = selObject as Outlook.MeetingItem; System.Windows.Forms.Form f = new FormTag(meeting, false); f.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; f.ShowDialog(); } }
private static void DeleteUserSelectedMarking(Outlook.MeetingItem item) { Debug.WriteLine("PspfMarkingsAddIn: DeleteUserSelectedMarking"); Debug.WriteLine("=============================================================================="); Outlook.UserProperties userProperties = null; Outlook.UserProperty userProperty = null; try { userProperties = item.UserProperties; userProperty = userProperties[TemporaryLabelPropertyName]; if (userProperty != null) { userProperty.Delete(); } } finally { if (userProperty != null) { Marshal.ReleaseComObject(userProperty); } if (userProperties != null) { Marshal.ReleaseComObject(userProperties); } } }
private void CurrentExplorer_Event() { Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder; String expMessage = "Your current folder is " + selectedFolder.Name + ".\n"; String itemMessage = "Item is unknown."; try { if (this.Application.ActiveExplorer().Selection.Count > 0) { Object selObject = this.Application.ActiveExplorer().Selection[1]; if (selObject is Outlook.MailItem) { Outlook.MailItem mailItem = (selObject as Outlook.MailItem); itemMessage = "The item is an e-mail message." + " The subject is " + mailItem.Subject + "."; mailItem.Display(false); } else if (selObject is Outlook.ContactItem) { Outlook.ContactItem contactItem = (selObject as Outlook.ContactItem); itemMessage = "The item is a contact." + " The full name is " + contactItem.Subject + "."; contactItem.Display(false); } else if (selObject is Outlook.AppointmentItem) { Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem); itemMessage = "The item is an appointment." + " The subject is " + apptItem.Subject + "."; } else if (selObject is Outlook.TaskItem) { Outlook.TaskItem taskItem = (selObject as Outlook.TaskItem); itemMessage = "The item is a task. The body is " + taskItem.Body + "."; } else if (selObject is Outlook.MeetingItem) { Outlook.MeetingItem meetingItem = (selObject as Outlook.MeetingItem); itemMessage = "The item is a meeting item. " + "The subject is " + meetingItem.Subject + "."; } } expMessage = expMessage + itemMessage; } catch (Exception ex) { expMessage = ex.Message; } MessageBox.Show(expMessage); }
private void ProcessNewMeetingItem(Outlook.MeetingItem meetingItem) { string vCalId = meetingItem.GetVCalId(); if (CrmId.IsValid(vCalId) && RestAPIWrapper.GetEntry(MeetingsSynchroniser.DefaultCrmModule, vCalId, new string[] { "id" }) != null) { meetingItem.GetAssociatedAppointment(false).SetCrmId(CrmId.Get(vCalId)); } }
public void setNewCategories(Outlook.MeetingItem meeting, string newCats) { checkTagsExists(newCats); if (meeting != null) { meeting.Categories = newCats; meeting.Save(); } }
private async void Button1_Click(object sender, RibbonControlEventArgs e) { var explorer = Globals.ThisAddIn.Application.ActiveExplorer(); var selectedFolder = explorer.CurrentFolder; var itemMessage = ""; try { if (explorer.Selection.Count > 0) { Object selObject = explorer.Selection[1]; if (selObject is Outlook.MailItem) { Outlook.MailItem mailItem = (selObject as Outlook.MailItem); await Globals.ThisAddIn.FromMail(mailItem); } else if (selObject is Outlook.ContactItem) { Outlook.ContactItem contactItem = (selObject as Outlook.ContactItem); itemMessage = "The item is a contact." + " The full name is " + contactItem.Subject + "."; } else if (selObject is Outlook.AppointmentItem) { Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem); itemMessage = "The item is an appointment." + " The subject is " + apptItem.Subject + "."; } else if (selObject is Outlook.TaskItem) { Outlook.TaskItem taskItem = (selObject as Outlook.TaskItem); itemMessage = "The item is a task. The body is " + taskItem.Body + "."; } else if (selObject is Outlook.MeetingItem) { Outlook.MeetingItem meetingItem = (selObject as Outlook.MeetingItem); itemMessage = "The item is a meeting item. " + "The subject is " + meetingItem.Subject + "."; } } if (!string.IsNullOrEmpty(itemMessage)) { MessageBox.Show(itemMessage); } } catch (Exception ex) //when (!Env.Debugging) { MessageBox.Show("An error occured sending to YouTrack.\n" + ex.Message, "Email to YouTrack error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <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> /// A meeting invitation is being sent; if we're going to sync it we should do so now and add the accept/decline links to the body before it actually is sent. /// </summary> /// <param name="meetingItem">The meeting whose invite(s) are being despatched.</param> /// <returns>true if the item was not null.</returns> private bool ProcessSentMeetingInvite(Outlook.MeetingItem meetingItem) { if (meetingItem != null) { Outlook.AppointmentItem appointment = meetingItem.GetAssociatedAppointment(false); var syncState = this.appointmentSynchroniser.AddOrGetSyncState(appointment); new SyncWaitDialog( this.appointmentSynchroniser, syncState, AppointmentSyncing.CrmModule, this.log) .ShowDialog(); } return(true); }
private static void UpdateAppointmentSubject(Outlook.MeetingItem item, string subject) { Outlook.AppointmentItem appointment = null; try { appointment = item.GetAssociatedAppointment(false); appointment.Subject = subject; } finally { if (appointment != null) { Marshal.ReleaseComObject(appointment); } } }
private static void SetHeader(Outlook.MeetingItem item, string headerName, string headerValue) { Outlook.PropertyAccessor accessor = null; try { accessor = item.PropertyAccessor; accessor.SetProperty(headerName, headerValue); } finally { if (accessor != null) { Marshal.ReleaseComObject(accessor); } } }
private static string GetSenderSmtpAddress(Outlook.MeetingItem item) { Outlook.Account account = null; try { account = item.SendUsingAccount; return(account.SmtpAddress); } finally { if (account != null) { Marshal.ReleaseComObject(account); } } }
/// <summary> /// MeetingItemから、宛先(Recipient)のリスト取得する /// </summary> /// <param name="Item">MeetingItemオブジェクト</param> /// <returns>List<Outlook.Recipient></returns> private static List <Outlook.Recipient> GetRecipientList(Outlook.MeetingItem item) { Outlook.Recipients recipients = item.Recipients; List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>(); for (int i = 1; i <= recipients.Count; i++) { if (recipients[i].Type == (int)Outlook.OlMeetingRecipientType.olResource) { // 拠点の空きリソースから選択したときに、拠点全部のリソースが宛先表示される現象の対策 if (recipients[i].Sendable) { recipientsList.Add(recipients[i]); } } else { recipientsList.Add(recipients[i]); } } return(recipientsList); }
/// <summary> /// Check meeting acceptances for the invitees of this `meeting`. /// </summary> /// <param name="meeting">The meeting.</param> /// <returns>the number of valid acceptance statuses found.</returns> public int UpdateMeetingAcceptances(Outlook.MeetingItem meeting) { return(meeting == null ? 0 : this.AddOrUpdateMeetingAcceptanceFromOutlookToCRM(meeting.GetAssociatedAppointment(false))); }
/// <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); }
/// <summary> /// When the user "drops" one or more email items into the calendar /// </summary> /// <param name="sender">Sender</param> /// <param name="e">DragEventArgs</param> private void lblCtrl_DragDrop(object sender, DragEventArgs e) { Label lblDay = sender as Label; if (sender != null) { Outlook.Explorer mailExpl = Globals.ThisAddIn.Application.ActiveExplorer(); List <string> attendees = new List <string>(); string curUserAddress = OutlookHelper.GetEmailAddress(Globals.ThisAddIn.Application.Session.CurrentUser); string body = String.Empty; string subject = String.Empty; foreach (object obj in mailExpl.Selection) { Outlook.MailItem mail = obj as Outlook.MailItem; if (mail != null) { subject = mail.Subject; body = mail.Body; if (mail.SenderEmailAddress != curUserAddress && !attendees.Contains(mail.SenderEmailAddress)) { attendees.Add(mail.SenderEmailAddress); } attendees.AddRange(OutlookHelper.GetRecipentsEmailAddresses(mail.Recipients, curUserAddress)); } else // It's not an email, let's see if it's a meeting instead { Outlook.MeetingItem meeting = obj as Outlook.MeetingItem; if (meeting != null) { subject = meeting.Subject; body = meeting.Body; if (meeting.SenderEmailAddress != curUserAddress && !attendees.Contains(meeting.SenderEmailAddress)) { attendees.Add(meeting.SenderEmailAddress); } attendees.AddRange(OutlookHelper.GetRecipentsEmailAddresses(meeting.Recipients, curUserAddress)); } else // It wasn't a meeting either, let's try with an appointment { Outlook.AppointmentItem appointment = obj as Outlook.AppointmentItem; if (appointment != null) { subject = appointment.Subject; body = appointment.Body; if (appointment.Organizer != curUserAddress && !attendees.Contains(appointment.Organizer)) { attendees.Add(appointment.Organizer); } attendees.AddRange(OutlookHelper.GetRecipentsEmailAddresses(appointment.Recipients, curUserAddress)); } } } } Outlook.AppointmentItem appt = Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem; attendees.ForEach(a => appt.Recipients.Add(a)); appt.Body = Environment.NewLine + Environment.NewLine + body; appt.Subject = subject; DateTime day = (DateTime)lblDay.Tag; DateTime now = DateTime.Now; appt.Start = OutlookHelper.RoundUp(new DateTime(day.Year, day.Month, day.Day, now.Hour, now.Minute, now.Second), TimeSpan.FromMinutes(15)); appt.Display(); } }
public void moveToArchive(Outlook.MeetingItem meeting) { }
public void moveToFollowup(Outlook.MeetingItem meeting) { }
private static FollowUpItem GetFollowUpItemInt(Outlook.MeetingItem a) { return(null); //moeilijk te implementeren -- FlagDate enz moeten gezet worden via mapi proptypes die ik niet vind }
public void followupMeeting(Outlook.MeetingItem meeting, int selection, bool archive) { }
private void ProcessMeetingItem(ref bool cancel, Outlook.MeetingItem item) { Debug.WriteLine("ProcessMeetingItem: Outlook.MeetingItem found"); Debug.WriteLine("=============================================================================="); if (!Config.Current.ApplyPspfBodyHeaderToMeetings && !Config.Current.ApplyPspfSubjectToMeetings && !Config.Current.ApplyPspfXHeaderToMeetings) { Debug.WriteLine("ProcessMeetingItem: No Meeting labels selected in config."); return; } ProtectiveMarking marking; // TODO: Never works here, need to get it some other way? //string pspfHeaderText = GetHeader(item, Config.Current.PspfHeaderName); //var pspfMarking = GetExistingMarking(pspfHeaderText, item.Subject); var userSelectedMarking = GetUserSelectedMarking(item); if (userSelectedMarking == null) { var pspfMarking = GetExistingMarking(null, item.Subject); if (pspfMarking == null || !pspfMarking.IsValid) { Debug.WriteLine("ProcessMeetingItem: No Existing Marking"); if (!Config.Current.RequireMeetingLabel) { Debug.WriteLine("ProcessMeetingItem: RequireMeetingLabel = false"); return; } marking = PromptUserForLabel(); if (marking == null) { cancel = true; return; } } else // pspfMarking is present and valid { // even with an existing subject label the xheader and body labels should still be applied. Debug.WriteLine("ProcessMeetingItem: Existing Marking Found"); //return; // TODO: Not satisfied with this return outcome. marking = pspfMarking; } } else { Debug.WriteLine("ProcessMeetingItem: New Label Selected"); // Clone the marking item so as to not alter the master list of protective markings marking = userSelectedMarking.Clone(); } if (string.IsNullOrWhiteSpace(marking.Origin)) { marking.Origin = GetSenderSmtpAddress(item); } if (Config.Current.ApplyPspfSubjectToMeetings) { string subject = ApplyMarkingToSubject(marking, item.Subject); item.Subject = subject; UpdateAppointmentSubject(item, subject); } if (Config.Current.ApplyPspfXHeaderToMeetings) { SetHeader(item, Config.Current.PspfHeaderName, marking.Header()); } if (Config.Current.ApplyPspfBodyHeaderToMeetings) { InsertPspfBodyHeader(item, marking); } DeleteUserSelectedMarking(item); // Save Mail Item to send item.Save(); }
/// <summary> /// Delete all mail items in folder /// </summary> /// <param name="mapiFolder">The folder need to delete all mails</param> public static void DeleteAllItemInMAPIFolder(Outlook.MAPIFolder mapiFolder) { if (mapiFolder.Items != null) { int count = mapiFolder.Items.Count; if (count == 0) { return; } else { try { do { if (mapiFolder.Items.GetFirst() is Outlook.MailItem) { Outlook.MailItem outlookMail = (Outlook.MailItem)mapiFolder.Items.GetFirst(); if (outlookMail != null) { outlookMail.Delete(); Marshal.ReleaseComObject(outlookMail); count--; } } else if (mapiFolder.Items.GetFirst() is Outlook.PostItem) { Outlook.PostItem outlookPost = (Outlook.PostItem)mapiFolder.Items.GetFirst(); if (outlookPost != null) { outlookPost.Delete(); Marshal.ReleaseComObject(outlookPost); count--; } } else if (mapiFolder.Items.GetFirst() is Outlook.MeetingItem) { Outlook.MeetingItem outlookMeeting = (Outlook.MeetingItem)mapiFolder.Items.GetFirst(); if (outlookMeeting != null) { outlookMeeting.Delete(); Marshal.ReleaseComObject(outlookMeeting); count--; } } else if (mapiFolder.Items.GetFirst() is Outlook.AppointmentItem) { Outlook.AppointmentItem outlookAppointment = (Outlook.AppointmentItem)mapiFolder.Items.GetFirst(); if (outlookAppointment != null) { outlookAppointment.Delete(); Marshal.ReleaseComObject(outlookAppointment); count--; } } }while (count > 0); } catch (Exception e) { throw new Exception(e.Message); } } } }