aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Stallman2015-08-12 11:25:26 -0400
committerRichard Stallman2015-08-12 11:25:26 -0400
commit79a169684dfad2c0bbb9fdbae539c1f30d9f0ac3 (patch)
tree57fca7c8973c977c6bbfe0b7cd70c54b90c7cd99
parent9bb90024e2c7383494e91dd58a21c78faea7255b (diff)
downloademacs-79a169684dfad2c0bbb9fdbae539c1f30d9f0ac3.tar.gz
emacs-79a169684dfad2c0bbb9fdbae539c1f30d9f0ac3.zip
Offer to combine multiple To or CC fields.
* sendmail.el (mail-combine-fields): New function. (mail-send): Call 'mail-combine-fields'.
-rw-r--r--lisp/mail/sendmail.el67
1 files changed, 67 insertions, 0 deletions
diff --git a/lisp/mail/sendmail.el b/lisp/mail/sendmail.el
index 2b9d8facae3..5b5ee4ec2c5 100644
--- a/lisp/mail/sendmail.el
+++ b/lisp/mail/sendmail.el
@@ -907,6 +907,8 @@ the user from the mailer."
907 (concat "\\(?:[[:space:];,]\\|\\`\\)" 907 (concat "\\(?:[[:space:];,]\\|\\`\\)"
908 (regexp-opt mail-mailing-lists t) 908 (regexp-opt mail-mailing-lists t)
909 "\\(?:[[:space:];,]\\|\\'\\)")))) 909 "\\(?:[[:space:];,]\\|\\'\\)"))))
910 (mail-combine-fields "To")
911 (mail-combine-fields "CC")
910 ;; If there are mailing lists defined 912 ;; If there are mailing lists defined
911 (when ml 913 (when ml
912 (save-excursion 914 (save-excursion
@@ -1075,6 +1077,71 @@ This function does not perform RFC2047 encoding."
1075 (goto-char fullname-start)))) 1077 (goto-char fullname-start))))
1076 (insert ")\n"))))) 1078 (insert ")\n")))))
1077 1079
1080(defun mail-combine-fields (field)
1081 "Offer to combine all FIELD fields in buffer into one FIELD field.
1082If this finds multiple FIELD fields, it asks the user whether
1083to combine them into one, and does so if the user says y."
1084 (let ((search-pattern (format "^%s[ \t]*:" field))
1085 first-to-end
1086 query-asked
1087 query-answer
1088 (old-point (point))
1089 (old-max (point-max)))
1090 (save-excursion
1091 (save-restriction
1092 (goto-char (point-min))
1093 (narrow-to-region (point-min) (mail-header-end))
1094 ;; Find the first FIELD field and record where it ends.
1095 (when (re-search-forward search-pattern nil t)
1096 (forward-line 1)
1097 (re-search-forward "^[^ \t]" nil t)
1098 (beginning-of-line)
1099 (setq first-to-end (point-marker))
1100 (set-marker-insertion-type first-to-end t)
1101 ;; Find each following FIELD field
1102 ;; and combine it with the first FIELD field.
1103 (while (re-search-forward search-pattern nil t)
1104 ;; For the second FIELD field, ask user to
1105 ;; approve combining them.
1106 ;; But if the user refuse to combine them, signal error.
1107 (unless query-asked
1108 (save-restriction
1109 ;; This is just so the screen doesn't change.
1110 (narrow-to-region (point-min) old-max)
1111 (goto-char old-point)
1112 (setq query-asked t)
1113 (if (y-or-n-p (format "Message contains multiple %s fields. Combine? " field))
1114 (setq query-answer t))))
1115 (when query-answer
1116 (let ((this-to-start (line-beginning-position))
1117 this-to-end
1118 this-to)
1119 (forward-line 1)
1120 (re-search-forward "^[^ \t]" nil t)
1121 (beginning-of-line)
1122 (setq this-to-end (point))
1123 ;; Get the text of this FIELD field.
1124 (setq this-to (buffer-substring this-to-start this-to-end))
1125 ;; Delete it.
1126 (delete-region this-to-start this-to-end)
1127 (save-excursion
1128 ;; Put a comma after the first FIELD field.
1129 (goto-char first-to-end)
1130 (forward-char -1)
1131 (insert ",")
1132 ;; Copy this one after it.
1133 (goto-char first-to-end)
1134 (save-excursion
1135 (insert this-to))
1136 ;; Replace the FIELD: with spaces.
1137 (looking-at search-pattern)
1138 ;; Try to preserve alignment of contents of the field
1139 (let ((prefix-length (length (match-string 0))))
1140 (replace-match " ")
1141 (dotimes (i (1- prefix-length))
1142 (insert " ")))))))
1143 (set-marker first-to-end nil))))))
1144
1078(defun mail-encode-header (beg end) 1145(defun mail-encode-header (beg end)
1079 "Encode the mail header between BEG and END according to RFC2047. 1146 "Encode the mail header between BEG and END according to RFC2047.
1080Return non-nil if and only if some part of the header is encoded." 1147Return non-nil if and only if some part of the header is encoded."