internal void VerifyEmail(Outlook.MailItem mailItem) { var encoding = GetEncodingFromMail(mailItem); var mail = string.Empty; // Try two different methods to get the message body try { mail = encoding.GetString( (byte[])mailItem.PropertyAccessor.GetProperty( "http://schemas.microsoft.com/mapi/string/{4E3A7680-B77A-11D0-9DA5-00C04FD65685}/Internet Charset Body/0x00000102")); } catch (Exception) { try { mail = (string)mailItem.PropertyAccessor.GetProperty( "http://schemas.microsoft.com/mapi/proptag/0x1000001F"); // PR_BODY } catch (Exception) { mail = mailItem.Body; } } if (Regex.IsMatch(mail, _pgpSignedHeader) == false) { MessageBox.Show( Localized.ErrorMsgNotSigned, Localized.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var context = new CryptoContext(PasswordCallback, _settings.Cipher, _settings.Digest); var crypto = new PgpCrypto(context); mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain; try { var message = string.Empty; if (crypto.Verify(_encoding.GetBytes(mail))) message = "** " + string.Format(Localized.MsgValidSig, crypto.Context.SignedByUserId, crypto.Context.SignedByKeyId) + "\n\n"; else message = "** " + string.Format(Localized.MsgInvalidSig, crypto.Context.SignedByUserId, crypto.Context.SignedByKeyId) + "\n\n"; mailItem.Body = message + mailItem.Body; } catch (PublicKeyNotFoundException) { var message = "** "+ Localized.MsgSigMissingPubKey+"\n\n"; mailItem.Body = message + mailItem.Body; } catch (Exception ex) { WriteErrorData("VerifyEmail", ex); MessageBox.Show( ex.Message, Localized.ErrorDialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal void VerifyEmail(Outlook.MailItem mailItem) { string mail = mailItem.Body; Outlook.OlBodyFormat mailType = mailItem.BodyFormat; if (Regex.IsMatch(mailItem.Body, _pgpSignedHeader) == false) { MessageBox.Show( "Outlook Privacy cannot help here.", "Mail is not signed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var Context = new CryptoContext(Passphrase); var Crypto = new PgpCrypto(Context); try { if (Crypto.Verify(_encoding.GetBytes(mail))) { Context = Crypto.Context; var message = "** Valid signature from \"" + Context.SignedByUserId + "\" with KeyId " + Context.SignedByKeyId + ".\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } else { Context = Crypto.Context; var message = "** Invalid signature from \"" + Context.SignedByUserId + "\" with KeyId " + Context.SignedByKeyId + ".\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } } catch (PublicKeyNotFoundException ex) { Context = Crypto.Context; var message = "** Unable to verify signature, missing public key.\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } catch (Exception ex) { this.Passphrase = null; WriteErrorData("VerifyEmail", ex); MessageBox.Show( ex.Message, "Outlook Privacy Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal void VerifyEmail(Outlook.MailItem mailItem) { string mail = mailItem.Body; Outlook.OlBodyFormat mailType = mailItem.BodyFormat; if (Regex.IsMatch(mailItem.Body, _pgpSignedHeader) == false) { MessageBox.Show( Localized.ErrorMsgNotSigned, "Mail is not signed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var Context = new CryptoContext(PasswordCallback, _settings.Cipher, _settings.Digest); var Crypto = new PgpCrypto(Context); try { if (Crypto.Verify(_encoding.GetBytes(mail))) { Context = Crypto.Context; var message = "** " + string.Format(Localized.MsgValidSig, Context.SignedByUserId, Context.SignedByKeyId) + "\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } else { Context = Crypto.Context; var message = "** " + string.Format(Localized.MsgInvalidSig, Context.SignedByUserId, Context.SignedByKeyId) + "\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } } catch (PublicKeyNotFoundException) { Context = Crypto.Context; string message = "** "+ Localized.MsgSigMissingPubKey+"\n\n"; if (mailType == Outlook.OlBodyFormat.olFormatPlain) { mailItem.Body = message + mailItem.Body; } } catch (Exception ex) { WriteErrorData("VerifyEmail", ex); MessageBox.Show( ex.Message, "Outlook Privacy Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }