GnusFormatFlowed

Gnus supports FormatFlowed text when both sending and receiving messages, but it doesn’t actually flow the text to windows boundaries like other mail clients do. Doing so requires heavy tinkering, as discussed below.

What is flowed text?

See FormatFlowed.

Gnus and the hard reality

format=flowed is enabled by default in Gnus, in the sense that encoded messages are correctly decoded and rewrapped according to ‘fill-flowed-display-column’ (which is usually ‘fill-column’), but that’s about it.

The easiest way to deal with format=flowed is to avoid it: if you want dynamic reflowing, simply unfold encoded lines to full length and setup article buffers to wrap:

(setq fill-flowed-display-column nil)

(add-hook 'gnus-article-mode-hook
  (lambda ()
    (setq
      truncate-lines nil
      word-wrap t)))

This will make Gnus behave as most other mail clients.

Composing or replying an article with long lines will choose a more resilient encoding such as ‘quoted-printable’ by default.

Just enabling ‘use-hard-newlines’ in ‘message-mode’ (as documented) is not enough to compose a flowed message and will most likely (as of 01/2011) kill all the formatting in your message.

Displaying and composing flowed messages

The following only works since Emacs 23, where ‘word-wrap’ and ‘truncate-lines’ was introduced. We can use Emacs’ built-in word-wrapping functionality and avoid ‘auto-fill’ and ‘use-hard-newlines’ entirely with the following (source):

(defun harden-newlines ()
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\n" nil t)
      (put-text-property (1- (point)) (point) 'hard t))))

(setq fill-flowed-display-column nil)

;; The following line is needed since emacs 24.1:
(setq gnus-treat-fill-long-lines nil)

(add-hook 'message-setup-hook
  (lambda ()
    (when message-this-is-mail
      (turn-off-auto-fill)
      (setq
	truncate-lines nil
	word-wrap t
	use-hard-newlines t))))

(add-hook 'message-send-hook
  (lambda ()
    (when use-hard-newlines
      (harden-newlines))))

(add-hook 'gnus-article-mode-hook
  (lambda ()
    (setq
      truncate-lines nil
      word-wrap t)))

The gotcha here is to avoid using ‘use-hard-newlines’ entirely, and simply compose a message with long lines. In ‘message-send-hook’ all newlines are converted to hard newlines, forcing Gnus to post a format=flowed messages, preserving the existing formatting.

By default, composing a flowed message is only enabled for mail, but it also works for groups coming from mail-to-news gateways such as GMane. Change ‘message-setup-hook’ accordingly if you wish to do that.


CategoryGnus