Hi, I've made some changes to warn the user about characters being
corrupted when sending mail via /usr/lib/sendmail or via SMTP under
XEmacs with MULE. (Based on suggestions by Stephen Turnbull, Hrvoje
Niksic, Adrian Aichner and possibly others I've forgotten, sorry.)
Since this problem only manifest itself when non-ascii and non-latin-1
characters are used I would not normally see this problem myself, so I
ask for beta testers.
How-to-help:
* Install the patch below and make sure the files are re-compiled,
loaded, and whatnot. (Should I install it in CVS?)
* For SMTP; evaluate
(require 'smtpmail)
(setq message-send-mail-function 'smtpmail-send-it
send-mail-function 'smtpmail-send-it
smtpmail-smtp-server (setq smtpmail-default-smtp-server "smtp.server"))
* For /usr/lib/sendmail; evaluate
(require 'sendmail)
(setq message-send-mail-function 'message-send-mail-with-sendmail
send-mail-function sendmail-send-it)
Things to test:
* Test it with your mail composer -- M-x mail or M-x message.
M-x mail SHOULD trigger the warning if you enter non-ascii,
non-latin-1 characters (cut'n'paste from C-h h). M-x message SHOULD
NOT trigger the warning (MIME should be used). Are there any other
mail composers using sendmail.el or smtpmail.el?
* Answer "yes" to the question to send mail anyway, verify that the
mail is corrupted (characters replace with `~').
* Does it ever interfer by misstake?
Many thanks!
2000-11-26 Simon Josefsson <sj(a)extundo.com>
* mail-utils.el (mail-y-or-n-p, mail-flatten-list)
(mail-check-safe-charset): New functions, from LMI's message.el.
* smtpmail.el (smtpmail-send-it): Use it; check for bad
characters.
* sendmail.el (sendmail-send-it): Use it; check for bad
characters.
2000-11-18 Simon Josefsson <sj(a)extundo.com>
* smtpmail.el (smtpmail-via-smtp): Use `set-process-coding-system'
instead of `set-buffer-process-coding-system'. Only use it if
`mule' or `file-coding' is provided.
(smtpmail-send-data-1): Call `encode-coding-string' only if `mule'
or `file-coding' is provided.
Index: smtpmail.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs-packages/libs/mail-lib/smtpmail.el,v
retrieving revision 1.4
diff -u -u -w -r1.4 smtpmail.el
--- smtpmail.el 2000/11/08 01:47:48 1.4
+++ smtpmail.el 2000/11/26 19:05:49
@@ -280,6 +280,9 @@
(smtpmail-deduce-address-list tembuf (point-min) delimline))
(kill-buffer smtpmail-address-buffer)
+ ;; XEmacs change
+ (mail-check-safe-charset)
+
(smtpmail-do-bcc delimline)
; Send or queue
(if (not smtpmail-queue-mail)
@@ -407,7 +410,9 @@
(save-excursion
(set-buffer process-buffer)
- (set-buffer-process-coding-system 'no-conversion-unix 'no-conversion-unix)
+ ;; XEmacs change
+ (if (or (featurep 'mule) (featurep 'file-coding))
+ (set-process-coding-system process 'no-conversion-unix 'no-conversion-unix))
(make-local-variable 'smtpmail-read-point)
(setq smtpmail-read-point (point-min))
@@ -700,7 +705,8 @@
(goto-char (point-max))
;; XEmacs change
- (if (and (featurep 'file-coding) (not (null smtpmail-code-conv-from)))
+ (if (and (or (featurep 'mule) (featurep 'file-coding))
+ (not (null smtpmail-code-conv-from)))
(setq data (encode-coding-string data smtpmail-code-conv-from)))
(if smtpmail-debug-info
--- mail-utils.el.~1.5.~ Mon Oct 23 10:35:45 2000
+++ mail-utils.el Sun Nov 26 15:25:11 2000
@@ -276,6 +276,40 @@
(substring s (match-beginning 3) (match-end 3)) " "
(mail-rfc822-time-zone time))))
+(defun mail-y-or-n-p (question &rest text)
+ "Ask QUESTION, displaying the rest of the arguments as strings in a buffer."
+ (setq text (mail-flatten-list text))
+ (save-window-excursion
+ (save-excursion
+ (with-output-to-temp-buffer " *SMTP information message*"
+ (set-buffer " *SMTP information message*")
+ (fundamental-mode) ; for Emacs 20.4+
+ (mapcar 'princ text)
+ (goto-char (point-min))))
+ (y-or-n-p question)))
+
+(defun mail-flatten-list (list)
+ "Return a new, flat list that contains all elements of LIST.
+
+\(mail-flatten-list '(1 (2 3 (4 5 (6))) 7))
+=> (1 2 3 4 5 6 7)"
+ (cond ((consp list)
+ (apply 'append (mapcar 'mail-flatten-list list)))
+ (list
+ (list list))))
+
+(defun mail-check-safe-charset ()
+ "Check that buffer contain characters that will be safely encoded."
+ (if (featurep 'mule)
+ (let ((bad-charsets (set-difference
+ (find-charset-region (point-min) (point-max))
+ '(ascii latin-iso8859-1 control-1))))
+ (when bad-charsets
+ (or (mail-y-or-n-p
+ "Your message contain invalid characters. Continue? "
+ "You're trying to send a message that contain characters\nin the
following character set:\n\n" (mapconcat 'symbol-name bad-charsets ",
") "\n\nThese characters cannot be send without proper encoding.
Please\nconsider using a MIME enabled mail composer (such as `message').\nContinuing
is likely to cause mail corruption.")
+ (error "Message contain invalid character"))))))
+
(provide 'mail-utils)
;;; mail-utils.el ends here
+++ sendmail.el Sun Nov 26 20:11:34 2000
@@ -705,6 +705,10 @@
(save-excursion
(set-buffer errbuf)
(erase-buffer))))
+
+ ;; XEmacs change
+ (mail-check-safe-charset)
+
(let ((default-directory "/")
exit-value)
(setq exit-value (apply 'call-process-region