Example #1
0
        private void CheckBCC(IMailItem mail)
        {
            // If the item already has a BCC, assume it's correct
            if (!string.IsNullOrEmpty(mail.BCC))
            {
                return;
            }

            // Grab the transport headers
            string headers = (string)mail.GetProperty(OutlookConstants.PR_TRANSPORT_MESSAGE_HEADERS);

            if (string.IsNullOrEmpty(headers))
            {
                return;
            }

            // Check if there's a bcc header
            Match match = RE_BCC.Match(headers);

            if (match.Groups.Count < 2)
            {
                return;
            }
            string bcc = match.Groups[1].Value;

            if (string.IsNullOrEmpty(bcc))
            {
                return;
            }

            // Add the recipient
            string decoded = bcc.DecodeQuotedPrintable();

            try
            {
                using (IRecipients recipients = mail.Recipients)
                {
                    foreach (string entry in decoded.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None))
                    {
                        using (IRecipient recip = CreateRecipient(recipients, entry))
                        {
                            recip.Type = MailRecipientType.BCC;
                        }
                    }
                }
            }
            finally
            {
                mail.Save();
            }
        }
Example #2
0
        private IRecipient CreateRecipient(IRecipients recipients, string decoded)
        {
            // First try to resolve directly
            IRecipient recipient = recipients.Add(decoded);

            if (recipient.Resolve())
            {
                return(recipient);
            }

            // Nope, remove and create with email
            recipient.Dispose();
            recipient = null;
            recipients.Remove(recipients.Count - 1);

            string displayName;
            string email = ParseBCCHeader(decoded, out displayName);

            // TODO: is it possible to use the display name?
            recipient = recipients.Add(email);
            recipient.Resolve();
            return(recipient);
        }