Exemplo n.º 1
0
        public ProtectiveMarking Clone()
        {
            Debug.WriteLine("ProtectiveMarking.Clone()");

            var protectiveMarking = new ProtectiveMarking()
            {
                DisplayName = DisplayName,
                // Current
                Version   = Version,
                Namespace = Namespace,
                SecurityClassification = SecurityClassification,
                Caveats = Caveats == null ? null : (string[])Caveats.Clone(),
                Expires = Expires,
                DownTo  = DownTo,
                InformationManagementMarkers = InformationManagementMarkers == null ? null : (string[])InformationManagementMarkers.Clone(),
                Note   = Note,
                Origin = Origin,
                // Deprecated
                Dlm = Dlm,
                // Msip
                MsipLabel = MsipLabel,
                // Body Header
                MailBodyHeaderAlign      = MailBodyHeaderAlign,
                MailBodyHeaderColour     = MailBodyHeaderColour,
                MailBodyHeaderFont       = MailBodyHeaderFont,
                MailBodyHeaderSizePoints = MailBodyHeaderSizePoints,
                MailBodyHeaderText       = MailBodyHeaderText,
            };

            return(protectiveMarking);
        }
        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);
                }
            }
        }
        private static ProtectiveMarking GetExistingMarking(string pspfHeaderText, string subject)
        {
            ProtectiveMarking existingMarking = null;

            // Preference the header because it contains more information (ie. Origin) ...
            if (!string.IsNullOrWhiteSpace(pspfHeaderText))
            {
                existingMarking = ProtectiveMarking.FromRegex(pspfHeaderText, Config.Current.RegexHeader, Config.Current.RegexOptionSet);
            }

            if (existingMarking == null || !existingMarking.IsValid)
            {
                existingMarking = ProtectiveMarking.FromRegex(subject, Config.Current.RegexSubject, Config.Current.RegexOptionSet);
            }

            return(existingMarking);
        }
        private static string ApplyMarkingToSubject(ProtectiveMarking marking, string subject)
        {
            // Remove existing subject marking
            if (!string.IsNullOrWhiteSpace(subject))
            {
                subject = Regex.Replace(subject, Config.Current.RegexSubject, string.Empty, Config.Current.RegexOptionSet);
            }

            // Apply new marking
            if (string.IsNullOrEmpty(subject))
            {
                subject = marking.Subject();
            }
            else
            {
                subject += " " + marking.Subject();
            }

            return(subject);
        }
Exemplo n.º 5
0
        public static bool Equals(ProtectiveMarking x, ProtectiveMarking y)
        {
            Debug.WriteLine("ProtectiveMarking.Equals()");

            // Compares only the things that matter to equivalence, ignores Notes & Origin (and MSIP attributes) ...

            if (x == null && y == null)
            {
                return(true);
            }

            if (x == null && y != null)
            {
                return(false);
            }

            if (x != null && y == null)
            {
                return(false);
            }

            if (!string.Equals(x.SecurityClassification, y.SecurityClassification, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (x.Caveats != null && y.Caveats != null)
            {
                if (x.Caveats.Length != y.Caveats.Length)
                {
                    return(false);
                }
                else if (x.Caveats.Length > 0 && y.Caveats.Length > 0)
                {
                    foreach (var caveat in x.Caveats)
                    {
                        if (Array.IndexOf(y.Caveats, caveat) == -1)
                        {
                            return(false);
                        }
                    }
                }
            }

            if (!string.Equals(x.Expires, y.Expires, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!string.Equals(x.DownTo, y.DownTo, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (x.InformationManagementMarkers != null && y.InformationManagementMarkers != null)
            {
                if (x.InformationManagementMarkers.Length != y.InformationManagementMarkers.Length)
                {
                    return(false);
                }
                else if (x.InformationManagementMarkers.Length > 0 && y.InformationManagementMarkers.Length > 0)
                {
                    foreach (var marker in x.InformationManagementMarkers)
                    {
                        if (Array.IndexOf(y.InformationManagementMarkers, marker) == -1)
                        {
                            return(false);
                        }
                    }
                }
            }

            if (!string.Equals(x.Dlm, y.Dlm, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public static ProtectiveMarking FromRegexMatch(Match match)
        {
            Debug.WriteLine("ProtectiveMarking.FromRegexMatch()");

            if (match == null)
            {
                return(null);
            }

            List <string> items;

            var marking = new ProtectiveMarking();

            if (!string.IsNullOrWhiteSpace(match.Groups["ver"].Value))
            {
                marking.Version = match.Groups["ver"].Value;
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["ns"].Value))
            {
                marking.Namespace = match.Groups["ns"].Value;
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["sec"].Value))
            {
                marking.SecurityClassification = match.Groups["sec"].Value;
            }

            var caveats = match.Groups["caveat"].Captures;

            items = new List <string>();
            foreach (Group item in caveats)
            {
                items.Add(item.Value);
            }
            if (items.Count > 0)
            {
                marking.Caveats = items.ToArray();
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["expires"].Value))
            {
                marking.Expires = match.Groups["expires"].Value;
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["downTo"].Value))
            {
                marking.DownTo = match.Groups["downTo"].Value;
            }

            var informationManagementMarkers = match.Groups["access"].Captures;

            items = new List <string>();
            foreach (Group item in informationManagementMarkers)
            {
                items.Add(item.Value);
            }
            if (items.Count > 0)
            {
                marking.InformationManagementMarkers = items.ToArray();
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["note"].Value))
            {
                marking.Note = match.Groups["note"].Value;
            }

            if (!string.IsNullOrWhiteSpace(match.Groups["origin"].Value))
            {
                marking.Origin = match.Groups["origin"].Value;
            }

            // Deprecated (2012.3)
            if (!string.IsNullOrWhiteSpace(match.Groups["dlm"].Value))
            {
                marking.Dlm     = match.Groups["dlm"].Value;
                marking.Version = PreviousVersion;
                marking.InformationManagementMarkers = null;
            }

            return(marking);
        }
        private static void AddMarkingHeaderToDocument(ProtectiveMarking marking, Word.Document document)
        {
            Debug.WriteLine("PspfMarkingsAddIn: AddMarkingHeaderToDocument");
            Debug.WriteLine("==============================================================================");

            Word.Range           range  = null;
            Word.Font            font   = null;
            Word.ParagraphFormat format = null;

            try
            {
                object start = 0;
                object end   = 0;

                // Move to start
                range = document.Range(ref start, ref end);

                // Insert Paragraph break
                range.InsertParagraphAfter();

                Marshal.ReleaseComObject(range);

                // Move to start
                range = document.Range(ref start, ref end);

                range.Text = marking.MailBodyHeaderText;

                font = range.Font;

                if (!string.IsNullOrWhiteSpace(marking.MailBodyHeaderColour))
                {
                    var colorConverter = new ColorConverter();

                    var color = (Color)colorConverter.ConvertFromString(marking.MailBodyHeaderColour);

                    font.Color = (Word.WdColor)(color.R + 0x100 * color.G + 0x10000 * color.B);
                }

                if (!string.IsNullOrWhiteSpace(marking.MailBodyHeaderSizePoints))
                {
                    font.Size = float.Parse(marking.MailBodyHeaderSizePoints);
                }

                if (!string.IsNullOrWhiteSpace(marking.MailBodyHeaderFont))
                {
                    font.Name = marking.MailBodyHeaderFont;
                }

                if (!string.IsNullOrWhiteSpace(marking.MailBodyHeaderAlign))
                {
                    format = range.ParagraphFormat;

                    switch (marking.MailBodyHeaderAlign.ToLowerInvariant())
                    {
                    case "center":
                    case "centre":
                    case "middle":
                        format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        break;

                    case "left":
                    case "normal":
                        format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                        break;

                    case "right":
                        format.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
                        break;

                    default:
                        Debug.WriteLine("Unexpected text alignment: " + marking.MailBodyHeaderAlign);
                        break;
                    }
                }

                // Force the edit to persist:
                document.Activate();
            }
            finally
            {
                if (format != null)
                {
                    Marshal.ReleaseComObject(format);
                }

                if (font != null)
                {
                    Marshal.ReleaseComObject(font);
                }

                if (range != null)
                {
                    Marshal.ReleaseComObject(range);
                }
            }
        }