Ejemplo n.º 1
0
 public void setNewCategories(Outlook.MeetingItem meeting, string newCats)
 {
     checkTagsExists(newCats);
     if (meeting != null)
     {
         meeting.Categories = newCats;
         meeting.Save();
     }
 }
        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();
        }