Exemple #1
0
 public static AddressEntry GetEventOrganizerOrNull(AppointmentItem source, IEntityMappingLogger logger, ILog generalLogger, int outlookMajorVersion)
 {
     try
     {
         if (outlookMajorVersion < 14)
         {
             // Microsoft recommends this way for Outlook 2007. May still work with Outlook 2010+
             using (var propertyAccessor = GenericComObjectWrapper.Create(source.PropertyAccessor))
             {
                 string organizerEntryID = propertyAccessor.Inner.BinaryToString(propertyAccessor.Inner.GetProperty(PR_SENT_REPRESENTING_ENTRYID));
                 return(Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(organizerEntryID));
             }
         }
         else
         {
             // NB this works with Outlook 2010 but crashes with Outlook 2007
             return(source.GetOrganizer());
         }
     }
     catch (COMException ex)
     {
         generalLogger.Warn("Can't get organizer of appointment", ex);
         logger.LogMappingWarning("Can't get organizer of appointment", ex);
         return(null);
     }
 }
        private String FormattedEvent(AppointmentItem item, String created, bool cancelled, bool expandRecurring)
        {
            String str = "BEGIN:VEVENT\r\n";

            str += "CREATED:" + created + "\r\n";

            // If we're not expanding recurring events, this is an exception, which means it's cancelled
            if (!expandRecurring)
            {
                str += "TRANSP:TRANSPARENT\r\n";
            }
            else
            {
                str += "TRANSP:OPAQUE\r\n";
            }

            str += wrapString("DESCRIPTION:" + item.Body.Replace("\r\n", "\\n").Replace(",", "\\,") + "\\n") + "\r\n";

            str += wrapString("SUMMARY:" + item.Subject) + "\r\n";

            str += wrapString("UID:" + item.GlobalAppointmentID) + "\r\n";

            str += wrapString("ORGANIZER;CN=\"" + item.GetOrganizer().Name + "\":mailto:" + item.GetOrganizer().PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x39FE001E").ToString()) + "\r\n";

            Recipients recipients = item.Recipients;

            if (recipients.Count > 1)
            {
                foreach (Recipient recipient in recipients)
                {
                    String recip = "ATTENDEE;CN=\"" + recipient.Name + "\"";
                    switch (recipient.Type)
                    {
                    case (int)NetOffice.OutlookApi.Enums.OlMeetingRecipientType.olOptional:
                        recip += ";ROLE=OPT-PARTICIPANT";
                        break;

                    case (int)NetOffice.OutlookApi.Enums.OlMeetingRecipientType.olRequired:
                        recip += ";ROLE=REQ-PARTICIPANT";
                        break;

                    case (int)NetOffice.OutlookApi.Enums.OlMeetingRecipientType.olOrganizer:
                        recip += ";ROLE=CHAIR";
                        break;

                    case (int)NetOffice.OutlookApi.Enums.OlMeetingRecipientType.olResource:
                        recip += ";ROLE=NON-PARTICIPANT";
                        break;
                    }
                    if (item.ResponseRequested)
                    {
                        recip += ";RSVP=TRUE";
                    }
                    switch (recipient.MeetingResponseStatus)
                    {
                    case NetOffice.OutlookApi.Enums.OlResponseStatus.olResponseAccepted:
                        recip += ";PARTSTAT=ACCEPTED";
                        break;

                    case NetOffice.OutlookApi.Enums.OlResponseStatus.olResponseDeclined:
                        recip += ";PARTSTAT=DECLINED";
                        break;

                    case NetOffice.OutlookApi.Enums.OlResponseStatus.olResponseNotResponded:
                        recip += ";PARTSTAT=NEEDS-ACTION";
                        break;

                    case NetOffice.OutlookApi.Enums.OlResponseStatus.olResponseOrganized:
                        recip += ";PARTSTAT=ACCEPTED";
                        break;

                    case NetOffice.OutlookApi.Enums.OlResponseStatus.olResponseTentative:
                        recip += ";PARTSTAT=TENTATIVE";
                        break;
                    }
                    str += wrapString(recip + ":mailto:" + recipient.PropertyAccessor.GetProperty(@"http://schemas.microsoft.com/mapi/proptag/0x39FE001E").ToString()) + "\r\n";
                }
            }

            if (item.Location.Length > 0)
            {
                str += wrapString("LOCATION:" + item.Location) + "\r\n";
            }

            {
                str += "PRIORITY:";
                switch (item.Importance)
                {
                case NetOffice.OutlookApi.Enums.OlImportance.olImportanceNormal:
                    str += "5" + "\r\n";
                    break;

                case NetOffice.OutlookApi.Enums.OlImportance.olImportanceLow:
                    str += "6" + "\r\n";
                    break;

                case NetOffice.OutlookApi.Enums.OlImportance.olImportanceHigh:
                    str += "1" + "\r\n";
                    break;
                }
            }
            {
                // SENSITIVITY
                switch (item.Sensitivity)
                {
                case NetOffice.OutlookApi.Enums.OlSensitivity.olNormal:
                    str += "CLASS:PUBLIC" + "\r\n";
                    break;

                case NetOffice.OutlookApi.Enums.OlSensitivity.olConfidential:
                    str += "CLASS:CONFIDENTIAL" + "\r\n";
                    break;

                case NetOffice.OutlookApi.Enums.OlSensitivity.olPrivate:
                    str += "CLASS:PRIVATE" + "\r\n";
                    break;

                case NetOffice.OutlookApi.Enums.OlSensitivity.olPersonal:
                    str += "CLASS:PRIVATE" + "\r\n";
                    break;
                }
            }

            if (item.AllDayEvent)
            {
                str += "DTSTART;VALUE=DATE:" + item.Start.ToString(@"yyyyMMdd") + "\r\n";
                str += "DTEND;VALUE=DATE:" + item.End.ToString(@"yyyyMMdd") + "\r\n";
            }
            else
            {
                str += "DTSTART;TZID=" + TZConvert.WindowsToIana(item.StartTimeZone.ID, "NL") + ":" + item.StartInStartTimeZone.ToString(@"yyyyMMdd\THHmmss") + "\r\n";
                str += "DTEND;TZID=" + TZConvert.WindowsToIana(item.EndTimeZone.ID, "NL") + ":" + item.EndInEndTimeZone.ToString(@"yyyyMMdd\THHmmss") + "\r\n";
            }

            str += "LAST-MODIFIED:" + item.LastModificationTime.ToUniversalTime().ToString(@"yyyyMMdd\THHmmssZ") + "\r\n";
            str += "DTSTAMP:" + item.CreationTime.ToUniversalTime().ToString(@"yyyyMMdd\THHmmssZ") + "\r\n";

            // Reminder
            if (item.ReminderSet)
            {
                str += "BEGIN:VALARM\r\n";

                str += "TRIGGER:-PT" + item.ReminderMinutesBeforeStart + "M\r\n";

                str += "ACTION:DISPLAY\r\n";
                str += "DESCRIPTION:Reminder\r\n";

                str += "END:VALARM\r\n";
            }

            if (expandRecurring && item.IsRecurring)
            {
                Console.WriteLine("Recurring meeting: " + item.Subject);

                RecurrencePattern rp = item.GetRecurrencePattern();

                str += "RRULE:";
                switch (rp.RecurrenceType)
                {
                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursDaily:
                    str += "FREQ=DAILY";
                    break;

                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursMonthly:
                    str += "FREQ=MONTHLY";
                    break;

                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursMonthNth:
                    str += "FREQ=MONTHLY";
                    break;

                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursWeekly:
                    str += "FREQ=WEEKLY";
                    break;

                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursYearly:
                    str += "FREQ=YEARLY";
                    break;

                case NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursYearNth:
                    break;
                }

                if (!rp.NoEndDate)
                {
                    // There is an end-date, either in occurrences or an end-date
                    if (rp.PatternEndDate != null)
                    {
                        str += ";UNTIL=" + rp.PatternEndDate.ToUniversalTime().ToString(@"yyyyMMdd\THHmmssZ");
                    }
                    else
                    {
                        str += ";COUNT=" + rp.Occurrences;
                    }
                }

                if (rp.Interval > 1)
                {
                    str += ";INTERVAL=" + rp.Interval;
                }

                string days = "";

                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olMonday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olMonday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "MO";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olTuesday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olTuesday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "TU";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olWednesday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olWednesday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "WE";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olThursday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olThursday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "TH";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olFriday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olFriday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "FR";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olSaturday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olSaturday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "SA";
                }
                if ((rp.DayOfWeekMask & NetOffice.OutlookApi.Enums.OlDaysOfWeek.olSunday) == NetOffice.OutlookApi.Enums.OlDaysOfWeek.olSunday)
                {
                    if (days.Length > 0)
                    {
                        days += ",";
                    }
                    days += "SU";
                }

                str += ";BYDAY=" + days;

                if (rp.RecurrenceType == NetOffice.OutlookApi.Enums.OlRecurrenceType.olRecursMonthNth)
                {
                    str += ";BYSETPOS=1";
                }

                str += "\r\n";

                str += "END:VEVENT" + "\r\n";

                Exceptions exceptions = rp.Exceptions;

                foreach (NetOffice.OutlookApi.Exception exc in exceptions)
                {
                    Console.WriteLine("Found an exception to item " + item.Subject);
                    try
                    {
                        str += FormattedEvent(exc.AppointmentItem, created, true, false);
                        Console.WriteLine("Wrote the exception");
                    }
                    catch (System.Runtime.InteropServices.COMException e)
                    {
                        // Let's ignore any errors for the moment, they come from items out of the current range i think...
                        Console.WriteLine("Error writing exception: " + e.Message);
                    }
                }
            }
            else
            {
                str += "END:VEVENT" + "\r\n";
            }

            return(str);
        }
 public static AddressEntry GetEventOrganizerOrNull (AppointmentItem source, IEntityMappingLogger logger, ILog generalLogger, int outlookMajorVersion)
 {
   try
   {
     if (outlookMajorVersion < 14)
     {
       // Microsoft recommends this way for Outlook 2007. May still work with Outlook 2010+
       using (var propertyAccessor = GenericComObjectWrapper.Create (source.PropertyAccessor))
       {
         string organizerEntryID = propertyAccessor.Inner.BinaryToString (propertyAccessor.Inner.GetProperty(PR_SENT_REPRESENTING_ENTRYID));
         return Globals.ThisAddIn.Application.Session.GetAddressEntryFromID (organizerEntryID);
       }
     }
     else
     {
       // NB this works with Outlook 2010 but crashes with Outlook 2007
       return source.GetOrganizer();
     }
   }
   catch (COMException ex)
   {
     generalLogger.Warn ("Can't get organizer of appointment", ex);
     logger.LogMappingWarning ("Can't get organizer of appointment", ex);
     return null;
   }
 }
Exemple #4
0
        public bool CheckObject(Object selObject)
        {
            if (DebugCheck(3))
            {
                System.Media.SoundPlayer player = new System.Media.SoundPlayer(resmgr.GetStream("fgth_welcome", ci));
                player.Play();
            }

            // selObject=AppointmentItem => Kalenderliste + Doppel-klick auf Kalendereinträge
            // selObject=MeetingItem => Meetings in Mailliste + Doppel-klick auf Mails

            /*
             * The AppointmentItem object represents a meeting, a one-time appointment, or a recurring appointment or meeting in the Calendar folder.
             * The AppointmentItem object includes methods that perform actions such as responding to or forwarding meeting requests,
             * and properties that specify meeting details such as the location and time.
             * */

            if (selObject is MeetingItem)
            {
                DPrint(I18n("RECOGNIZED") + " - MeetingItem", 2);
                selObject = (selObject as MeetingItem).GetAssociatedAppointment(false);
            }

            if (!(selObject is AppointmentItem) || (selObject as AppointmentItem) == null || (selObject as AppointmentItem).EntryID == null)
            {
                if (selObject == null)
                {
                    DPrint("selObject " + I18n("IS_NULL"), 0);
                }
                return(false);
            }
            // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentItem#properties
            AppointmentItem apptItem = (selObject as AppointmentItem);
            // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentitem.meetingstatus
            bool isMeeting = (MeetingStatusToInt(apptItem.MeetingStatus) != 0);

            DPrint(I18n("RECOGNIZED") + " - AppointmentItem: isMeeting=" + isMeeting.ToString(), 2);

            // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentitem.organizer
            string Organizer_Name;
            string Organizer_Full = null;

            if (apptItem.Organizer == null && MeetingStatusToInt(apptItem.MeetingStatus) == 1)  // my own non-sended meeting, in this case GetOrganizer() is obsolete.
            {
                Organizer_Name = apptItem.SendUsingAccount.UserName;
                DPrint("apptItem.SendUsingAccount.DisplayName=\"" + apptItem.SendUsingAccount.DisplayName + "\"", 2);
            }
            else
            {
                // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentitem.getorganizer
                string[] result = AdressEntryNameExtract(apptItem.GetOrganizer());
                if (result != null)
                {
                    Organizer_Name = result[0];
                    Organizer_Full = result[1];
                }
                else
                {
                    Organizer_Name = apptItem.Organizer;
                }
            }
            DPrint("apptItem.MeetingStatus=\"" + apptItem.MeetingStatus + "\"", 2);
            if (apptItem.GetOrganizer().Name != apptItem.Organizer)
            {
                DPrint("DIFF: apptItem.GetOrganizer().Name=\"" + apptItem.GetOrganizer().Name + "\" / apptItem.Organizer=\"" + apptItem.Organizer + "\"", 0);
            }
            Organizer_Name = Organizer_Name ?? "[" + I18n("ORGANIZER") + " " + I18n("IS_EMPTY") + "]";
            Organizer_Full = Organizer_Full ?? Organizer_Name;

            // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentitem.subject
            string Subject = apptItem.Subject;

            // https://docs.microsoft.com/de-de/office/vba/api/outlook.appointmentItem.recipients
            string[] output = Recipients(apptItem.Recipients, (apptItem.GetOrganizer() != null ? apptItem.GetOrganizer().ID : ""));
            //string[] output = Recipients(apptItem.Recipients, "");
            // TODO testing is this without organizer?? testing with somebody
            string RequiredAttendees_Names = output[0];
            string OptionalAttendees_Names = output[1];
            string RequiredAttendees_Full  = output[2];
            string OptionalAttendees_Full  = output[3];
            bool   Acceptable = MeetingStatusToInt(apptItem.MeetingStatus) == 3;
            int    Importance = MessgageImportanceToInt(apptItem.Importance);

            Subject = Subject ?? "[" + I18n("SUBJECT") + " " + I18n("IS_EMPTY") + "]";

            SetElements(new string[] { Subject, Organizer_Name, RequiredAttendees_Names, OptionalAttendees_Names }, 0);
            SetElements(new string[] { I18n("SUBJECT"), I18n("ORGANIZER"), I18n("REQUIRED_ATTENDEES"), I18n("OPTIONAL_ATTENDEES") }, 1);
            SetElements(new string[] { Subject, Organizer_Full, RequiredAttendees_Full, OptionalAttendees_Full }, 2);
            // https://docs.microsoft.com/de-de/office/vba/api/outlook.meetingitem.importance
            CheckImage((System.Drawing.Bitmap)resmgr.GetObject("important", ci), 0, Importance == 2);
            SetElement(Acceptable && setting.AcceptButton ? I18n("ACCEPT") : null, 4, 0);
            SetElement(Acceptable && setting.AcceptButton ? I18n("ACCEPT") : null, 4, 1);
            SetElement(Acceptable && setting.AcceptButton ? I18n("ACCEPT") : null, 4, 2);
            SetElement(Acceptable && setting.AcceptButton ? apptItem : null, 4);
            return(true);
        }