Mercurial > emacs
comparison lisp/gnus/rfc2047.el @ 50881:b042c57894f8
(rfc2047-header-encoding-alist): Add Followup-To.
(rfc2047-encode-message-header): Fold when encoding not necessary.
(rfc2047-encode-region): Skip \n as whitespace.
(rfc2047-fold-region): Fix whitespace regexps. Don't break just
after the header name.
(rfc2047-unfold-region): Fix regexp and whitespace-skipping.
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 07 May 2003 17:26:31 +0000 |
parents | 9cd6016af581 |
children | 695cf19ef79e |
comparison
equal
deleted
inserted
replaced
50880:c4ef9b4c327f | 50881:b042c57894f8 |
---|---|
1 ;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages | 1 ;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages |
2 ;; Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc. | 2 ;; Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc. |
3 | 3 |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | 4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp> | 5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp> |
6 ;; This file is part of GNU Emacs. | 6 ;; This file is part of GNU Emacs. |
7 | 7 |
37 (require 'mail-prsvr) | 37 (require 'mail-prsvr) |
38 (require 'base64) | 38 (require 'base64) |
39 (autoload 'mm-body-7-or-8 "mm-bodies") | 39 (autoload 'mm-body-7-or-8 "mm-bodies") |
40 | 40 |
41 (defvar rfc2047-header-encoding-alist | 41 (defvar rfc2047-header-encoding-alist |
42 '(("Newsgroups" . nil) | 42 '(("Newsgroups\\|Followup-To" . nil) |
43 ("Message-ID" . nil) | 43 ("Message-ID" . nil) |
44 ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\\)" . | 44 ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\\)" . |
45 address-mime) | 45 address-mime) |
46 (t . mime)) | 46 (t . mime)) |
47 "*Header/encoding method alist. | 47 "*Header/encoding method alist. |
133 (let (alist elem method) | 133 (let (alist elem method) |
134 (while (not (eobp)) | 134 (while (not (eobp)) |
135 (save-restriction | 135 (save-restriction |
136 (rfc2047-narrow-to-field) | 136 (rfc2047-narrow-to-field) |
137 (if (not (rfc2047-encodable-p)) | 137 (if (not (rfc2047-encodable-p)) |
138 (if (and (eq (mm-body-7-or-8) '8bit) | 138 (prog1 |
139 (mm-multibyte-p) | 139 (if (and (eq (mm-body-7-or-8) '8bit) |
140 (mm-coding-system-p | 140 (mm-multibyte-p) |
141 (car message-posting-charset))) | 141 (mm-coding-system-p |
142 ;; 8 bit must be decoded. | 142 (car message-posting-charset))) |
143 ;; Is message-posting-charset a coding system? | 143 ;; 8 bit must be decoded. |
144 (mm-encode-coding-region | 144 (mm-encode-coding-region |
145 (point-min) (point-max) | 145 (point-min) (point-max) |
146 (car message-posting-charset))) | 146 (mm-charset-to-coding-system |
147 (car message-posting-charset)))) | |
148 ;; No encoding necessary, but folding is nice | |
149 (rfc2047-fold-region | |
150 (save-excursion | |
151 (goto-char (point-min)) | |
152 (skip-chars-forward "^:") | |
153 (when (looking-at ": ") | |
154 (forward-char 2)) | |
155 (point)) | |
156 (point-max))) | |
147 ;; We found something that may perhaps be encoded. | 157 ;; We found something that may perhaps be encoded. |
148 (setq method nil | 158 (setq method nil |
149 alist rfc2047-header-encoding-alist) | 159 alist rfc2047-header-encoding-alist) |
150 (while (setq elem (pop alist)) | 160 (while (setq elem (pop alist)) |
151 (when (or (and (stringp (car elem)) | 161 (when (or (and (stringp (car elem)) |
228 ;; `address-mime' case -- take care of quoted words, comments. | 238 ;; `address-mime' case -- take care of quoted words, comments. |
229 (with-syntax-table rfc2047-syntax-table | 239 (with-syntax-table rfc2047-syntax-table |
230 (let ((start (point)) ; start of current token | 240 (let ((start (point)) ; start of current token |
231 end ; end of current token | 241 end ; end of current token |
232 ;; Whether there's an encoded word before the current | 242 ;; Whether there's an encoded word before the current |
233 ;; tpken, either immediately or separated by space. | 243 ;; token, either immediately or separated by space. |
234 last-encoded) | 244 last-encoded) |
235 (goto-char (point-min)) | 245 (goto-char (point-min)) |
236 (condition-case nil ; in case of unbalanced quotes | 246 (condition-case nil ; in case of unbalanced quotes |
237 ;; Look for rfc2822-style: sequences of atoms, quoted | 247 ;; Look for rfc2822-style: sequences of atoms, quoted |
238 ;; strings, specials, whitespace. (Specials mustn't be | 248 ;; strings, specials, whitespace. (Specials mustn't be |
239 ;; encoded.) | 249 ;; encoded.) |
240 (while (not (eobp)) | 250 (while (not (eobp)) |
241 (setq start (point)) | 251 (setq start (point)) |
242 ;; Skip whitespace. | 252 ;; Skip whitespace. |
243 (unless (= 0 (skip-chars-forward " \t")) | 253 (unless (= 0 (skip-chars-forward " \t\n")) |
244 (setq start (point))) | 254 (setq start (point))) |
245 (cond | 255 (cond |
246 ((not (char-after))) ; eob | 256 ((not (char-after))) ; eob |
247 ;; else token start | 257 ;; else token start |
248 ((eq ?\" (char-syntax (char-after))) | 258 ((eq ?\" (char-syntax (char-after))) |
362 (save-restriction | 372 (save-restriction |
363 (narrow-to-region b e) | 373 (narrow-to-region b e) |
364 (goto-char (point-min)) | 374 (goto-char (point-min)) |
365 (let ((break nil) | 375 (let ((break nil) |
366 (qword-break nil) | 376 (qword-break nil) |
377 (first t) | |
367 (bol (save-restriction | 378 (bol (save-restriction |
368 (widen) | 379 (widen) |
369 (mm-point-at-bol)))) | 380 (mm-point-at-bol)))) |
370 (while (not (eobp)) | 381 (while (not (eobp)) |
371 (when (and (or break qword-break) (> (- (point) bol) 76)) | 382 (when (and (or break qword-break) (> (- (point) bol) 76)) |
372 (goto-char (or break qword-break)) | 383 (goto-char (or break qword-break)) |
373 (setq break nil | 384 (setq break nil |
374 qword-break nil) | 385 qword-break nil) |
375 (if (looking-at " \t") | 386 (if (looking-at "[ \t]") |
376 (insert ?\n) | 387 (insert ?\n) |
377 (insert "\n ")) | 388 (insert "\n ")) |
378 (setq bol (1- (point))) | 389 (setq bol (1- (point))) |
379 ;; Don't break before the first non-LWSP characters. | 390 ;; Don't break before the first non-LWSP characters. |
380 (skip-chars-forward " \t") | 391 (skip-chars-forward " \t") |
390 (forward-char 1))) | 401 (forward-char 1))) |
391 ((eq (char-after) ?\r) | 402 ((eq (char-after) ?\r) |
392 (forward-char 1)) | 403 (forward-char 1)) |
393 ((memq (char-after) '(? ?\t)) | 404 ((memq (char-after) '(? ?\t)) |
394 (skip-chars-forward " \t") | 405 (skip-chars-forward " \t") |
395 (setq break (1- (point)))) | 406 (if first |
407 ;; Don't break just after the header name. | |
408 (setq first nil) | |
409 (setq break (1- (point))))) | |
396 ((not break) | 410 ((not break) |
397 (if (not (looking-at "=\\?[^=]")) | 411 (if (not (looking-at "=\\?[^=]")) |
398 (if (eq (char-after) ?=) | 412 (if (eq (char-after) ?=) |
399 (forward-char 1) | 413 (forward-char 1) |
400 (skip-chars-forward "^ \t\n\r=")) | 414 (skip-chars-forward "^ \t\n\r=")) |
404 (skip-chars-forward "^ \t\n\r")))) | 418 (skip-chars-forward "^ \t\n\r")))) |
405 (when (and (or break qword-break) (> (- (point) bol) 76)) | 419 (when (and (or break qword-break) (> (- (point) bol) 76)) |
406 (goto-char (or break qword-break)) | 420 (goto-char (or break qword-break)) |
407 (setq break nil | 421 (setq break nil |
408 qword-break nil) | 422 qword-break nil) |
409 (if (looking-at " \t") | 423 (if (looking-at "[ \t]") |
410 (insert ?\n) | 424 (insert ?\n) |
411 (insert "\n ")) | 425 (insert "\n ")) |
412 (setq bol (1- (point))) | 426 (setq bol (1- (point))) |
413 ;; Don't break before the first non-LWSP characters. | 427 ;; Don't break before the first non-LWSP characters. |
414 (skip-chars-forward " \t") | 428 (skip-chars-forward " \t") |
424 (mm-point-at-bol))) | 438 (mm-point-at-bol))) |
425 (eol (mm-point-at-eol)) | 439 (eol (mm-point-at-eol)) |
426 leading) | 440 leading) |
427 (forward-line 1) | 441 (forward-line 1) |
428 (while (not (eobp)) | 442 (while (not (eobp)) |
429 (looking-at "[ \t]*") | 443 (if (and (looking-at "[ \t]") |
430 (setq leading (- (match-end 0) (match-beginning 0))) | 444 (< (- (mm-point-at-eol) bol) 76)) |
431 (if (< (- (mm-point-at-eol) bol leading) 76) | 445 (delete-region eol (progn |
432 (progn | 446 (goto-char eol) |
433 (goto-char eol) | 447 (skip-chars-forward "\r\n") |
434 (delete-region eol (progn | 448 (point))) |
435 (skip-chars-forward "[ \t\n\r]+") | |
436 (1- (point))))) | |
437 (setq bol (mm-point-at-bol))) | 449 (setq bol (mm-point-at-bol))) |
438 (setq eol (mm-point-at-eol)) | 450 (setq eol (mm-point-at-eol)) |
439 (forward-line 1))))) | 451 (forward-line 1))))) |
440 | 452 |
441 (defun rfc2047-b-encode-region (b e) | 453 (defun rfc2047-b-encode-region (b e) |