Automatically setting a Keywords: header in Gnus' follow ups #gnus #activitypub #elisp #nntp

🕗︎ - 2023-06-25

I have added support for "Mention" "tag"s in my little ActivityPub/NNTP-server, so now I just need to actually follow the convention of setting such a tag when replying.

How to do that? A message hook to the rescue:

(defun illuminant-follow-up-keywords ()
  "Add the From: user id to Keywords:"
  (let ((group (or gnus-newsgroup-name "")))
    (when (and (string-match "nntp.illuminant" group) message-reply-headers)
      (let ((from (mail-header-from message-reply-headers)))
        (when from
          (let ((userid (cdr (gnus-extract-address-components from))))
            (when userid
              (message-add-header (format "Keywords: @%s" (car userid))))))))))

(add-hook 'message-setup-hook 'illuminant-follow-up-keywords)

If the newsgroup is from illuminant, it is a follow up, and there is a fediverse user name to extract in From:, add a Keywords: header with that user id, for a mention.

To keep all the mentions of the parent article, what I really need is to grab Keywords: from there and add the From:, so this is the hook needed:

(defun illuminant-follow-up-keywords ()
  "Add the From: user id to Keywords: from the article being followed up."
  (when (and (string-match "nntp.illuminant" (or gnus-newsgroup-name "") nil t)
    (let ((from (mail-header-from message-reply-headers))
          (keywords (save-excursion
                      (set-buffer message-reply-buffer)
                        (let ((start (gnus-article-goto-header "Keywords")))
                          (if start
                              (list (buffer-substring-no-properties (+ 1 start) (line-end-position)))
      (when from
        (let ((userid (cdr (gnus-extract-address-components from))))
          (when userid
            (setq keywords (append keywords (list (format "@%s" (car userid))))))))
      (when keywords
        (message-add-header (format "Keywords: %s" (mapconcat 'identity keywords ", ")))))))

- Adam Sjøgren 🕝︎ - 2023-07-05


Add comment

To avoid spam many websites make you fill out a CAPTCHA, or log in via an account at a corporation such as Twitter, Facebook, Google or even Microsoft GitHub.

I have chosen to use a more old school method of spam prevention.

To post a comment here, you need to:

¹ Such as Thunderbird, Pan, slrn, tin or Gnus (part of Emacs).

Or, you can fill in this form: