diff --git a/lib/decrypt_mails.rb b/lib/decrypt_mails.rb index 5d6d317..e86db77 100644 --- a/lib/decrypt_mails.rb +++ b/lib/decrypt_mails.rb @@ -11,6 +11,15 @@ module InstanceMethods def receive_with_encryption(email, options={}) + # Extract useful metadata for logging + sender_email = email.from.to_a.first.to_s.strip + # We need to store this before decryption, because after decryption + # email.encrypted? == false + encrypted = email.encrypted? + # Sometimes this isn't available after decryption. This seems like a bug, + # so extract it here so we're guaranteed to have it + message_id = email.message_id + # encrypt and check validity of signature if email.encrypted? email = email.decrypt( @@ -32,7 +41,6 @@ def receive_with_encryption(email, options={}) # compare identity of signature with sender if valid valid = false - sender_email = email.from.to_a.first.to_s.strip user = User.find_by_mail sender_email if sender_email.present? key = Pgpkey.find_by user_id: user.id signatures.each do |s| @@ -41,10 +49,17 @@ def receive_with_encryption(email, options={}) end # error on invalid signature - if Setting.plugin_openpgp['signature_needed'] and not valid - if logger - logger.info "MailHandler: ignoring emails with invalid signature" - end + ignored = !!(Setting.plugin_openpgp['signature_needed'] and not valid) + + if logger + logger.info "MailHandler: received email from #{sender_email} " + + "with Message-ID #{message_id}: " + + "encrypted=#{encrypted}, " + + "valid=#{valid}, "+ + "ignored=#{ignored}" + end + + if ignored return false end @@ -53,4 +68,4 @@ def receive_with_encryption(email, options={}) end end -end \ No newline at end of file +end