From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.bugs Subject: bug#22014: 24.4; RFC 5322 Disallows Multiple 'To' Fields in Mail Headers Date: Thu, 26 Nov 2015 09:46:32 -0500 Message-ID: References: <878u5lvld1.fsf@dellarge.pearlmutter.net> Reply-To: rms@gnu.org NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1448549299 19958 80.91.229.3 (26 Nov 2015 14:48:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Nov 2015 14:48:19 +0000 (UTC) Cc: 22014@debbugs.gnu.org To: "Barak A. Pearlmutter" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 26 15:48:06 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a1xq9-00069i-UR for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Nov 2015 15:48:06 +0100 Original-Received: from localhost ([::1]:51620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xqC-0001R0-AK for geb-bug-gnu-emacs@m.gmane.org; Thu, 26 Nov 2015 09:48:08 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xq8-0001Qu-8W for bug-gnu-emacs@gnu.org; Thu, 26 Nov 2015 09:48:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1xq6-00023M-QR for bug-gnu-emacs@gnu.org; Thu, 26 Nov 2015 09:48:04 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35561) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xq6-000238-NE for bug-gnu-emacs@gnu.org; Thu, 26 Nov 2015 09:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1a1xq6-00054z-Fx for bug-gnu-emacs@gnu.org; Thu, 26 Nov 2015 09:48:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Richard Stallman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 26 Nov 2015 14:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22014 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 22014-submit@debbugs.gnu.org id=B22014.144854922219435 (code B ref 22014); Thu, 26 Nov 2015 14:48:02 +0000 Original-Received: (at 22014) by debbugs.gnu.org; 26 Nov 2015 14:47:02 +0000 Original-Received: from localhost ([127.0.0.1]:53502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a1xp7-00053M-67 for submit@debbugs.gnu.org; Thu, 26 Nov 2015 09:47:01 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:39987) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a1xp3-00053D-Px for 22014@debbugs.gnu.org; Thu, 26 Nov 2015 09:46:58 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1xp2-0001ZN-92 for 22014@debbugs.gnu.org; Thu, 26 Nov 2015 09:46:57 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:40134) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1xou-0001XV-Qn; Thu, 26 Nov 2015 09:46:48 -0500 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1a1xoe-00069k-3C; Thu, 26 Nov 2015 09:46:32 -0500 In-reply-to: <878u5lvld1.fsf@dellarge.pearlmutter.net> (barak@pearlmutter.net) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:109286 Archived-At: [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > The ‘To’, ‘CC’, and ‘BCC’ fields can appear any number of times ... > This is in contravention to RFC 5322, the current standard for mail > headers. What year did they do that? I suspect they changed the spec subsequently to our implementing it. > On the other hand, it would be nice if Emacs > tried to be conformant in this regard, by detecting and consolidating > multiple To:, CC:, or BCC: fields. Emacs must not override the user's decision! The reason to us multiple To or CC headers is to group the names in a meaningful way. Consolidating them automatically would make the header less clear. I wrote this change for sendmail.el, which asks the user what to do. But I have not felt like fighting with git to install it. Would someone else like to install it? Maybe the same code can work for msg mode; I never use that. diff -u /home/rms/emacs-git/build-aug-12/lisp/mail/sendmail.el.\~1\~ /home/rms/emacs-git/build-aug-12/lisp/mail/sendmail.el --- /home/rms/emacs-git/build-aug-12/lisp/mail/sendmail.el.~1~ 2015-08-12 11:15:38.785756144 -0400 +++ /home/rms/emacs-git/build-aug-12/lisp/mail/sendmail.el 2015-08-12 11:24:47.048474821 -0400 @@ -907,6 +907,8 @@ (concat "\\(?:[[:space:];,]\\|\\`\\)" (regexp-opt mail-mailing-lists t) "\\(?:[[:space:];,]\\|\\'\\)")))) + (mail-combine-fields "To") + (mail-combine-fields "CC") ;; If there are mailing lists defined (when ml (save-excursion @@ -1075,6 +1077,71 @@ (goto-char fullname-start)))) (insert ")\n"))))) +(defun mail-combine-fields (field) + "Offer to combine all FIELD fields in buffer into one FIELD field. +If this finds multiple FIELD fields, it asks the user whether +to combine them into one, and does so if the user says y." + (let ((search-pattern (format "^%s[ \t]*:" field)) + first-to-end + query-asked + query-answer + (old-point (point)) + (old-max (point-max))) + (save-excursion + (save-restriction + (goto-char (point-min)) + (narrow-to-region (point-min) (mail-header-end)) + ;; Find the first FIELD field and record where it ends. + (when (re-search-forward search-pattern nil t) + (forward-line 1) + (re-search-forward "^[^ \t]" nil t) + (beginning-of-line) + (setq first-to-end (point-marker)) + (set-marker-insertion-type first-to-end t) + ;; Find each following FIELD field + ;; and combine it with the first FIELD field. + (while (re-search-forward search-pattern nil t) + ;; For the second FIELD field, ask user to + ;; approve combining them. + ;; But if the user refuse to combine them, signal error. + (unless query-asked + (save-restriction + ;; This is just so the screen doesn't change. + (narrow-to-region (point-min) old-max) + (goto-char old-point) + (setq query-asked t) + (if (y-or-n-p (format "Message contains multiple %s fields. Combine? " field)) + (setq query-answer t)))) + (when query-answer + (let ((this-to-start (line-beginning-position)) + this-to-end + this-to) + (forward-line 1) + (re-search-forward "^[^ \t]" nil t) + (beginning-of-line) + (setq this-to-end (point)) + ;; Get the text of this FIELD field. + (setq this-to (buffer-substring this-to-start this-to-end)) + ;; Delete it. + (delete-region this-to-start this-to-end) + (save-excursion + ;; Put a comma after the first FIELD field. + (goto-char first-to-end) + (forward-char -1) + (insert ",") + ;; Copy this one after it. + (goto-char first-to-end) + (save-excursion + (insert this-to)) + ;; Replace the FIELD: with spaces. + (looking-at search-pattern) + ;; Try to preserve alignment of contents of the field + (let ((prefix-length (length (match-string 0)))) + (replace-match " ") + (dotimes (i (1- prefix-length)) + (insert " "))))))) + (set-marker first-to-end nil)))))) + (defun mail-encode-header (beg end) "Encode the mail header between BEG and END according to RFC2047. Return non-nil if and only if some part of the header is encoded." Diff finished. Wed Nov 25 21:50:29 2015 -- Dr Richard Stallman President, Free Software Foundation (gnu.org, fsf.org) Internet Hall-of-Famer (internethalloffame.org) Skype: No way! See stallman.org/skype.html.