4

I configured emacs to automatically sign emails:

(add-hook 'mu4e-compose-mode-hook 'mml-secure-message-sign)

However, mailing lists often add a footer to the message and that breaks the signature. Also some people are consistently confused by the attached signatures, and in these cases I'd prefer if the message wasn't signed. (These people are not going to check the signature anyway.)

What's the best way to implement a blacklist of email addresses such that emails to addresses on that list are not automatically signed?

2
+50

The following will prevent messages to email addresses in blacklist-addresses from invoking mml-secure-message-sign.

(defvar blacklist-addresses nil
  "List of email addresses (as strings) to blacklist for
  `mml-secure-message-sign'.")

(defun secure-sign-maybe ()
  "Use `mml-secure-message-sign' unless the addressee is in the
`blacklist-addresses'."
  (let ((addresses (mapcar (lambda (address)
                             (when (string-match
                                    "\\(<?\\)\\([^@< ]+@[^@> ]+\\)\\(>?\\)"
                                    address)
                               (match-string 2 address)))
                           ;; (split-string (message-field-value "To")
                           ;;               "," t "[[:blank:]]+"))))
                           (split-string (concat (message-field-value "To")
                                                 ", "
                                                 (message-field-value "Cc"))
                                         "," t "[[:blank:]]+"))))
    ;; skip secure signing when an address is blacklisted
    (unless (delq nil (mapcar (lambda (address)
                                (car (member address blacklist-addresses)))
                              addresses))
      (mml-secure-message-sign))))

(add-hook 'message-send-hook #'secure-sign-maybe)

Right now, the code looks for addresses in the "To" and "Cc" fields. If you want it to check only the "To" field, comment out the existing call to split-string and uncomment the commented version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.