Gnus development mailing list
 help / color / mirror / Atom feed
From: Toby Speight <streapadair@gmx.net>
Subject: Re: Integrating message-utils.el into Gnus?
Date: 28 Apr 2001 02:34:48 +0100	[thread overview]
Message-ID: <s8pudxlscn.fsf@lanber.cam.eu.citrix.com> (raw)
In-Reply-To: <874rval15a.fsf@fulmine.dhs.org>

0> In article <874rval15a.fsf@fulmine.dhs.org>,
0> Matthias Wiehl <URL:mailto:mwiehl@gmx.de> ("Matthias") wrote:

Matthias> Holger Schauer [1] provides a file called message-utils.el
Matthias> [2].  It contains a few complementary functions for use with
Matthias> Gnus' message-mode.
Matthias>
Matthias> [1] <URL:mailto:Holger.Schauer@gmx.de>
Matthias> [2] <URL:http://www.coling.uni-freiburg.de/%7eschauer/resources/emacs/message-utils.el.gz>
Matthias>
Matthias>
Matthias> Personally, I find three of those functions extraordinarily
Matthias> useful:
Matthias>
Matthias>   o  `message-change-subject' asks for a new subject, and
Matthias>      modifies the message's Subject header in a way that is
Matthias>      RFC 1036bis compliant: `new subject (was: old subject)'.
Matthias>
Matthias>   o  `message-strip-subject-was' can be hooked into
Matthias>      `message-header-setup-hook'.  It strips `(was: old
Matthias>      subject)' from the Subject header (which is what user
Matthias>      agents are supposed to do) as far as I know) when
Matthias>      entering message-mode.  Both slrn and tin do this
Matthias>      out-of-the-box.

I've posted my equivalent here before - perhaps someone has the time
to compare the two and combine the best bits of each?


Matthias>   o  `message-xpost-fup2' asks for a newsgroup name (providing
Matthias>      tab-completion via gnus-newsrc-alist).  This name is then
Matthias>      appended to the Newsgroups header, and the Followup-To
Matthias>      header is modified to contain only the given newsgroup
Matthias>      name as its value.  Furthermore, a customizable note is
Matthias>      inserted in the message body, saying that a Followup-To
Matthias>      header has been set.

I haven't written anything to do that - sounds cool.

Here's my code:

  -- snip here --

(defvar message-change-subject-ignored-prefixes
  "\\`\\(\\(Re\\|Fwd\\|AW\\)\\>[.:]?\\|\\[[^][]+\\]\\|[ \t\r]+\\)"
  "Regexp matching things to be stripped when following up.")

(defun message-change-subject-interactively (&optional new-subj) ;gnus-subject-interactive
  "Change the Subject, bracketing with \"(was...)\" if necessary."
  (interactive "*")
  (undo-boundary)
  (save-excursion
    (save-restriction
      (message-narrow-to-headers-or-head)
      (let* ((subject (message-fetch-field "Subject"))
             (case-fold-search t))
        (if (null subject)
            (setq new-subj (read-from-minibuffer "New Subject: "))
          ;; There was already a subject
          (when (string-match "\\s-+\\'" subject) ; remove trailing spaces
            (setq subject (replace-match "" t t subject)))
          (if (and (not new-subj) (string-match "^[Rr][Ee]\\>" subject))
              ;; only ask if it wasn't our subject
              (setq new-subj
                    (read-from-minibuffer (concat "New Subject: (was " subject ") "))))
          ;; new-subj is nil if we already have an original subject (not starting with "Re:")
          ;; It is a string if we are following-up (so might want to remove "(was ...)")
          (if (and new-subj
                   (or                  ;(re-search-forward "\\s-*\\((was\\>.*\\)" subject-end t)
                    (string-match "\\s-*\\([[(,;]\\s-*was\\>.*\\)" subject)
                    (string-match "\\s-*\\<\\(was:?\\s-+[Rr][Ee]:.*\\)" subject)
                    (string-match "\\s-*[[(,;]\\s-*\\([Rr][Ee]:.*\\)" subject))
                   (or (not (string= new-subj "")) ; if replacing, force removal
                       (y-or-n-p (concat "Remove \"" (match-string 1 subject) "\" from Subject: line? "))))
              (setq new-subj (replace-match "" t t subject)
                    subject nil))
          (if (or (null new-subj) (string= "" new-subj))
              ;; No true change in subject
              (setq new-subj subject
                    subject nil)
            ;;  User changed the subject
            ;; first undo RFC-822 line-wrap
            (while (and subject (string-match "\n[ \t]" subject))
              (setq subject (replace-match " " t t subject)))
            ;; might be a followup to a forwarded message, so trim [...] too
            (while (and subject (string-match message-change-subject-ignored-prefixes subject))
              (setq subject (replace-match "" t t subject)))
            ;; Trim subject line to 75 chars (leaving room for a recipient to add "Re: ")
            ;; "Subject: "(9) + new-subj + "(was: "(6) + subject + "...)"(1 or 4)  <=75
            ;; means subject<=(59 - new-subj) or trim to (56 - new-subj)
            (if (and subject (> (length subject) (- 59 (length new-subj))))
                (let ((maxlen (- 56 (length new-subj))))
                  (if (<= maxlen 0)
                      (setq subject "...")
                    ;; keep one extra char, so we know if last char is a word-boundary
                    (setq subject (substring subject 0 (1+ maxlen)))
                    (if (string-match "\\s-*\\(\\B.\\|\\<.\\)*\\'" subject)
                        (setq subject (replace-match "..." t t subject))))))))
        (widen)
        (when new-subj
          (if (and subject (not (string= "" subject)))
              (setq new-subj (concat new-subj " (was: " subject ")")))
          (message-goto-subject)
          (message-delete-line)
          (insert "Subject: " new-subj "\n"))))))

  -- snip here --

It's suitable for use in `message-send-hook' (that's how I use it), in
which case it asks you to confirm the subject if you've not obviously
edited it from the existing value.  If you change it, it removes any
(was...)  string and replaces it with one made from the old subject.
It attempts to truncate the new (was...)  string to fit an 80-column
screen, preferably at word boundaries.

If you leave the subject unchanged, and there was a "(was...)" section
if offers (y-or-n-p) to remove it for you.



  reply	other threads:[~2001-04-28  1:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-27 20:48 Matthias Wiehl
2001-04-28  1:34 ` Toby Speight [this message]
2002-02-14  0:17 ` Reiner Steib
2002-02-14  1:04   ` ShengHuo ZHU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s8pudxlscn.fsf@lanber.cam.eu.citrix.com \
    --to=streapadair@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).