Mercurial > emacs
comparison lisp/mail/smtpmail.el @ 103287:e501499f857c
* mail/smtpmail.el: Indent code properly to make it more readable.
author | Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> |
---|---|
date | Mon, 25 May 2009 01:11:46 +0000 |
parents | b83a02b58e7f |
children | 328150f0cf76 |
comparison
equal
deleted
inserted
replaced
103286:b05973aa4a3f | 103287:e501499f857c |
---|---|
44 ;;(setq smtpmail-starttls-credentials | 44 ;;(setq smtpmail-starttls-credentials |
45 ;; '(("YOUR SMTP HOST" 25 "~/.my_smtp_tls.key" "~/.my_smtp_tls.cert"))) | 45 ;; '(("YOUR SMTP HOST" 25 "~/.my_smtp_tls.key" "~/.my_smtp_tls.cert"))) |
46 ;; Where the 25 equals the value of `smtpmail-smtp-service', it can be an | 46 ;; Where the 25 equals the value of `smtpmail-smtp-service', it can be an |
47 ;; integer or a string, just as long as they match (eq). | 47 ;; integer or a string, just as long as they match (eq). |
48 | 48 |
49 ;; To queue mail, set smtpmail-queue-mail to t and use | 49 ;; To queue mail, set `smtpmail-queue-mail' to t and use |
50 ;; smtpmail-send-queued-mail to send. | 50 ;; `smtpmail-send-queued-mail' to send. |
51 | 51 |
52 ;; Modified by Stephen Cranefield <scranefield@infoscience.otago.ac.nz>, | 52 ;; Modified by Stephen Cranefield <scranefield@infoscience.otago.ac.nz>, |
53 ;; 22/6/99, to support SMTP Authentication by the AUTH=LOGIN mechanism. | 53 ;; 22/6/99, to support SMTP Authentication by the AUTH=LOGIN mechanism. |
54 ;; See http://help.netscape.com/products/server/messaging/3x/info/smtpauth.html | 54 ;; See http://help.netscape.com/products/server/messaging/3x/info/smtpauth.html |
55 ;; Rewritten by Simon Josefsson to use same credential variable as AUTH | 55 ;; Rewritten by Simon Josefsson to use same credential variable as AUTH |
120 Don't bother to set this unless you have get an error like: | 120 Don't bother to set this unless you have get an error like: |
121 Sending failed; SMTP protocol error | 121 Sending failed; SMTP protocol error |
122 when sending mail, and the *trace of SMTP session to <somewhere>* | 122 when sending mail, and the *trace of SMTP session to <somewhere>* |
123 buffer includes an exchange like: | 123 buffer includes an exchange like: |
124 RCPT TO: <someone> | 124 RCPT TO: <someone> |
125 501 <someone>: recipient address must contain a domain | 125 501 <someone>: recipient address must contain a domain." |
126 " | |
127 :type '(choice (const nil) string) | 126 :type '(choice (const nil) string) |
128 :group 'smtpmail) | 127 :group 'smtpmail) |
129 | 128 |
130 (defcustom smtpmail-debug-info nil | 129 (defcustom smtpmail-debug-info nil |
131 "Whether to print info in buffer *trace of SMTP session to <somewhere>*. | 130 "Whether to print info in buffer *trace of SMTP session to <somewhere>*. |
167 `password' (a string, or nil to query the user when needed). If you | 166 `password' (a string, or nil to query the user when needed). If you |
168 need to enter a `realm' too, add it to the user string, so that it | 167 need to enter a `realm' too, add it to the user string, so that it |
169 looks like `user@realm'." | 168 looks like `user@realm'." |
170 :type '(choice file | 169 :type '(choice file |
171 (repeat (list (string :tag "Server") | 170 (repeat (list (string :tag "Server") |
172 (integer :tag "Port") | 171 (integer :tag "Port") |
173 (string :tag "Username") | 172 (string :tag "Username") |
174 (choice (const :tag "Query when needed" nil) | 173 (choice (const :tag "Query when needed" nil) |
175 (string :tag "Password"))))) | 174 (string :tag "Password"))))) |
176 :version "22.1" | 175 :version "22.1" |
177 :group 'smtpmail) | 176 :group 'smtpmail) |
178 | 177 |
179 (defcustom smtpmail-starttls-credentials '(("" 25 "" "")) | 178 (defcustom smtpmail-starttls-credentials '(("" 25 "" "")) |
244 (select-message-coding-system))))) | 243 (select-message-coding-system))))) |
245 (unwind-protect | 244 (unwind-protect |
246 (save-excursion | 245 (save-excursion |
247 (set-buffer tembuf) | 246 (set-buffer tembuf) |
248 (erase-buffer) | 247 (erase-buffer) |
249 ;; Use the same buffer-file-coding-system as in the mail | 248 ;; Use the same `buffer-file-coding-system' as in the mail |
250 ;; buffer, otherwise any write-region invocations (e.g., in | 249 ;; buffer, otherwise any `write-region' invocations (e.g., in |
251 ;; mail-do-fcc below) will annoy with asking for a suitable | 250 ;; mail-do-fcc below) will annoy with asking for a suitable |
252 ;; encoding. | 251 ;; encoding. |
253 (set-buffer-file-coding-system smtpmail-code-conv-from nil t) | 252 (set-buffer-file-coding-system smtpmail-code-conv-from nil t) |
254 (insert-buffer-substring mailbuf) | 253 (insert-buffer-substring mailbuf) |
255 (goto-char (point-max)) | 254 (goto-char (point-max)) |
257 (or (= (preceding-char) ?\n) | 256 (or (= (preceding-char) ?\n) |
258 (insert ?\n)) | 257 (insert ?\n)) |
259 ;; Change header-delimiter to be what sendmail expects. | 258 ;; Change header-delimiter to be what sendmail expects. |
260 (mail-sendmail-undelimit-header) | 259 (mail-sendmail-undelimit-header) |
261 (setq delimline (point-marker)) | 260 (setq delimline (point-marker)) |
262 ;; (sendmail-synch-aliases) | 261 ;; (sendmail-synch-aliases) |
263 (if mail-aliases | 262 (if mail-aliases |
264 (expand-mail-aliases (point-min) delimline)) | 263 (expand-mail-aliases (point-min) delimline)) |
265 (goto-char (point-min)) | 264 (goto-char (point-min)) |
266 ;; ignore any blank lines in the header | 265 ;; ignore any blank lines in the header |
267 (while (and (re-search-forward "\n\n\n*" delimline t) | 266 (while (and (re-search-forward "\n\n\n*" delimline t) |
268 (< (point) delimline)) | 267 (< (point) delimline)) |
269 (replace-match "\n")) | 268 (replace-match "\n")) |
270 (let ((case-fold-search t)) | 269 (let ((case-fold-search t)) |
271 ;; We used to process Resent-... headers here, | 270 ;; We used to process Resent-... headers here, |
272 ;; but it was not done properly, and the job | 271 ;; but it was not done properly, and the job |
273 ;; is done correctly in smtpmail-deduce-address-list. | 272 ;; is done correctly in `smtpmail-deduce-address-list'. |
274 ;; Don't send out a blank subject line | 273 ;; Don't send out a blank subject line |
275 (goto-char (point-min)) | 274 (goto-char (point-min)) |
276 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t) | 275 (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t) |
277 (replace-match "") | 276 (replace-match "") |
278 ;; This one matches a Subject just before the header delimiter. | 277 ;; This one matches a Subject just before the header delimiter. |
355 (if (eval mail-mailer-swallows-blank-line) | 354 (if (eval mail-mailer-swallows-blank-line) |
356 (newline)) | 355 (newline)) |
357 ;; Find and handle any FCC fields. | 356 ;; Find and handle any FCC fields. |
358 (goto-char (point-min)) | 357 (goto-char (point-min)) |
359 (if (re-search-forward "^FCC:" delimline t) | 358 (if (re-search-forward "^FCC:" delimline t) |
360 ;; Force mail-do-fcc to use the encoding of the mail | 359 ;; Force `mail-do-fcc' to use the encoding of the mail |
361 ;; buffer to encode outgoing messages on FCC files. | 360 ;; buffer to encode outgoing messages on FCC files. |
362 (let ((coding-system-for-write smtpmail-code-conv-from)) | 361 (let ((coding-system-for-write smtpmail-code-conv-from)) |
363 (mail-do-fcc delimline))) | 362 (mail-do-fcc delimline))) |
364 (if mail-interactive | 363 (if mail-interactive |
365 (with-current-buffer errbuf | 364 (with-current-buffer errbuf |
366 (erase-buffer)))) | 365 (erase-buffer)))) |
367 ;; | 366 ;; |
368 ;; | |
369 ;; | |
370 (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*")) | 367 (setq smtpmail-address-buffer (generate-new-buffer "*smtp-mail*")) |
371 (setq smtpmail-recipient-address-list | 368 (setq smtpmail-recipient-address-list |
372 (smtpmail-deduce-address-list tembuf (point-min) delimline)) | 369 (smtpmail-deduce-address-list tembuf (point-min) delimline)) |
373 (kill-buffer smtpmail-address-buffer) | 370 (kill-buffer smtpmail-address-buffer) |
374 | 371 |
375 (smtpmail-do-bcc delimline) | 372 (smtpmail-do-bcc delimline) |
376 ; Send or queue | 373 ;; Send or queue |
377 (if (not smtpmail-queue-mail) | 374 (if (not smtpmail-queue-mail) |
378 (if (not (null smtpmail-recipient-address-list)) | 375 (if (not (null smtpmail-recipient-address-list)) |
379 (if (not (smtpmail-via-smtp | 376 (if (not (smtpmail-via-smtp |
380 smtpmail-recipient-address-list tembuf)) | 377 smtpmail-recipient-address-list tembuf)) |
381 (error "Sending failed; SMTP protocol error")) | 378 (error "Sending failed; SMTP protocol error")) |
422 ;;;###autoload | 419 ;;;###autoload |
423 (defun smtpmail-send-queued-mail () | 420 (defun smtpmail-send-queued-mail () |
424 "Send mail that was queued as a result of setting `smtpmail-queue-mail'." | 421 "Send mail that was queued as a result of setting `smtpmail-queue-mail'." |
425 (interactive) | 422 (interactive) |
426 (with-temp-buffer | 423 (with-temp-buffer |
427 ;;; Get index, get first mail, send it, update index, get second | 424 ;; Get index, get first mail, send it, update index, get second |
428 ;;; mail, send it, etc... | 425 ;; mail, send it, etc... |
429 (let ((file-msg "") | 426 (let ((file-msg "") |
430 (qfile (expand-file-name smtpmail-queue-index-file | 427 (qfile (expand-file-name smtpmail-queue-index-file |
431 smtpmail-queue-dir))) | 428 smtpmail-queue-dir))) |
432 (insert-file-contents qfile) | 429 (insert-file-contents qfile) |
433 (goto-char (point-min)) | 430 (goto-char (point-min)) |
451 (delete-file file-msg) | 448 (delete-file file-msg) |
452 (delete-file (concat file-msg ".el")) | 449 (delete-file (concat file-msg ".el")) |
453 (delete-region (point-at-bol) (point-at-bol 2))) | 450 (delete-region (point-at-bol) (point-at-bol 2))) |
454 (write-region (point-min) (point-max) qfile)))) | 451 (write-region (point-min) (point-max) qfile)))) |
455 | 452 |
456 ;(defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer) | 453 ;; (defun smtpmail-via-smtp (host,port,sender,destination,smtpmail-text-buffer) |
457 | 454 |
458 (defun smtpmail-fqdn () | 455 (defun smtpmail-fqdn () |
459 (if smtpmail-local-domain | 456 (if smtpmail-local-domain |
460 (concat (system-name) "." smtpmail-local-domain) | 457 (concat (system-name) "." smtpmail-local-domain) |
461 (system-name))) | 458 (system-name))) |
528 (file-regular-p | 525 (file-regular-p |
529 (setq cred-cert (expand-file-name cred-cert)))) | 526 (setq cred-cert (expand-file-name cred-cert)))) |
530 (list "--x509keyfile" cred-key "--x509certfile" cred-cert))))) | 527 (list "--x509keyfile" cred-key "--x509certfile" cred-cert))))) |
531 (starttls-open-stream "SMTP" process-buffer host port))))) | 528 (starttls-open-stream "SMTP" process-buffer host port))))) |
532 | 529 |
533 ;; password-read autoloads password-cache. | 530 ;; `password-read' autoloads password-cache. |
534 (declare-function password-cache-add "password-cache" (key password)) | 531 (declare-function password-cache-add "password-cache" (key password)) |
535 | 532 |
536 (defun smtpmail-try-auth-methods (process supported-extensions host port) | 533 (defun smtpmail-try-auth-methods (process supported-extensions host port) |
537 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions))) | 534 (let* ((mechs (cdr-safe (assoc 'auth supported-extensions))) |
538 (mech (car (smtpmail-intersection mechs smtpmail-auth-supported))) | 535 (mech (car (smtpmail-intersection mechs smtpmail-auth-supported))) |
550 port-name))) | 547 port-name))) |
551 (when hostentry | 548 (when hostentry |
552 (list host port | 549 (list host port |
553 (netrc-get hostentry "login") | 550 (netrc-get hostentry "login") |
554 (netrc-get hostentry "password")))) | 551 (netrc-get hostentry "password")))) |
555 ;; else, try smtpmail-find-credentials since | 552 ;; else, try `smtpmail-find-credentials' since |
556 ;; smtpmail-auth-credentials is not a string | 553 ;; `smtpmail-auth-credentials' is not a string |
557 (smtpmail-find-credentials | 554 (smtpmail-find-credentials |
558 smtpmail-auth-credentials host port)))) | 555 smtpmail-auth-credentials host port)))) |
559 (prompt (when cred (format "SMTP password for %s:%s: " | 556 (prompt (when cred (format "SMTP password for %s:%s: " |
560 (smtpmail-cred-server cred) | 557 (smtpmail-cred-server cred) |
561 (smtpmail-cred-port cred)))) | 558 (smtpmail-cred-port cred)))) |
582 ;; new line characters) as a response from the | 579 ;; new line characters) as a response from the |
583 ;; client, and the rest as distinct commands. | 580 ;; client, and the rest as distinct commands. |
584 | 581 |
585 ;; In my case, the response string is 80 characters | 582 ;; In my case, the response string is 80 characters |
586 ;; long. Without the no-line-break option for | 583 ;; long. Without the no-line-break option for |
587 ;; base64-encode-sting, only the first 76 characters | 584 ;; `base64-encode-string', only the first 76 characters |
588 ;; are taken as a response to the server, and the | 585 ;; are taken as a response to the server, and the |
589 ;; authentication fails. | 586 ;; authentication fails. |
590 (encoded (base64-encode-string response t))) | 587 (encoded (base64-encode-string response t))) |
591 (smtpmail-send-command process (format "%s" encoded)) | 588 (smtpmail-send-command process (format "%s" encoded)) |
592 (if (or (null (car (setq ret (smtpmail-read-response process)))) | 589 (if (or (null (car (setq ret (smtpmail-read-response process)))) |
637 (defun smtpmail-via-smtp (recipient smtpmail-text-buffer) | 634 (defun smtpmail-via-smtp (recipient smtpmail-text-buffer) |
638 (let ((process nil) | 635 (let ((process nil) |
639 (host (or smtpmail-smtp-server | 636 (host (or smtpmail-smtp-server |
640 (error "`smtpmail-smtp-server' not defined"))) | 637 (error "`smtpmail-smtp-server' not defined"))) |
641 (port smtpmail-smtp-service) | 638 (port smtpmail-smtp-service) |
642 ;; smtpmail-mail-address should be set to the appropriate | 639 ;; `smtpmail-mail-address' should be set to the appropriate |
643 ;; buffer-local value by the caller, but in case not: | 640 ;; buffer-local value by the caller, but in case not: |
644 (envelope-from (or smtpmail-mail-address | 641 (envelope-from (or smtpmail-mail-address |
645 (and mail-specify-envelope-from | 642 (and mail-specify-envelope-from |
646 (mail-envelope-from)) | 643 (mail-envelope-from)) |
647 user-mail-address)) | 644 user-mail-address)) |
674 | 671 |
675 | 672 |
676 (if (or (null (car (setq greeting (smtpmail-read-response process)))) | 673 (if (or (null (car (setq greeting (smtpmail-read-response process)))) |
677 (not (integerp (car greeting))) | 674 (not (integerp (car greeting))) |
678 (>= (car greeting) 400)) | 675 (>= (car greeting) 400)) |
679 (throw 'done nil) | 676 (throw 'done nil)) |
680 ) | |
681 | 677 |
682 (let ((do-ehlo t) | 678 (let ((do-ehlo t) |
683 (do-starttls t)) | 679 (do-starttls t)) |
684 (while do-ehlo | 680 (while do-ehlo |
685 ;; EHLO | 681 ;; EHLO |
686 (smtpmail-send-command process (format "EHLO %s" (smtpmail-fqdn))) | 682 (smtpmail-send-command process (format "EHLO %s" (smtpmail-fqdn))) |
687 | 683 |
688 (if (or (null (car (setq response-code | 684 (if (or (null (car (setq response-code |
689 (smtpmail-read-response process)))) | 685 (smtpmail-read-response process)))) |
690 (not (integerp (car response-code))) | 686 (not (integerp (car response-code))) |
691 (>= (car response-code) 400)) | 687 (>= (car response-code) 400)) |
692 (progn | 688 (progn |
693 ;; HELO | 689 ;; HELO |
694 (smtpmail-send-command | 690 (smtpmail-send-command |
695 process (format "HELO %s" (smtpmail-fqdn))) | 691 process (format "HELO %s" (smtpmail-fqdn))) |
696 | 692 |
697 (if (or (null (car (setq response-code | 693 (if (or (null (car (setq response-code |
698 (smtpmail-read-response process)))) | 694 (smtpmail-read-response process)))) |
699 (not (integerp (car response-code))) | 695 (not (integerp (car response-code))) |
700 (>= (car response-code) 400)) | 696 (>= (car response-code) 400)) |
701 (throw 'done nil))) | 697 (throw 'done nil))) |
702 (dolist (line (cdr (cdr response-code))) | 698 (dolist (line (cdr (cdr response-code))) |
703 (let ((name | 699 (let ((name |
704 (with-case-table ascii-case-table | 700 (with-case-table ascii-case-table |
705 (mapcar (lambda (s) (intern (downcase s))) | 701 (mapcar (lambda (s) (intern (downcase s))) |
706 (split-string (substring line 4) "[ ]"))))) | 702 (split-string (substring line 4) "[ ]"))))) |
707 (and (eq (length name) 1) | 703 (and (eq (length name) 1) |
708 (setq name (car name))) | 704 (setq name (car name))) |
709 (and name | 705 (and name |
710 (cond ((memq (if (consp name) (car name) name) | 706 (cond ((memq (if (consp name) (car name) name) |
711 '(verb xvrb 8bitmime onex xone | 707 '(verb xvrb 8bitmime onex xone |
712 expn size dsn etrn | 708 expn size dsn etrn |
713 enhancedstatuscodes | 709 enhancedstatuscodes |
714 help xusr | 710 help xusr |
715 auth=login auth starttls)) | 711 auth=login auth starttls)) |
716 (setq supported-extensions | 712 (setq supported-extensions |
717 (cons name supported-extensions))) | 713 (cons name supported-extensions))) |
718 (smtpmail-warn-about-unknown-extensions | 714 (smtpmail-warn-about-unknown-extensions |
719 (message "Unknown extension %s" name))))))) | 715 (message "Unknown extension %s" name))))))) |
720 | 716 |
721 (if (and do-starttls | 717 (if (and do-starttls |
722 (smtpmail-find-credentials smtpmail-starttls-credentials host port) | 718 (smtpmail-find-credentials smtpmail-starttls-credentials host port) |
723 (member 'starttls supported-extensions) | 719 (member 'starttls supported-extensions) |
724 (numberp (process-id process))) | 720 (numberp (process-id process))) |
725 (progn | 721 (progn |
726 (smtpmail-send-command process (format "STARTTLS")) | 722 (smtpmail-send-command process (format "STARTTLS")) |
727 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | 723 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
728 (not (integerp (car response-code))) | 724 (not (integerp (car response-code))) |
729 (>= (car response-code) 400)) | 725 (>= (car response-code) 400)) |
730 (throw 'done nil)) | 726 (throw 'done nil)) |
731 (starttls-negotiate process) | 727 (starttls-negotiate process) |
732 (setq do-starttls nil)) | 728 (setq do-starttls nil)) |
733 (setq do-ehlo nil)))) | 729 (setq do-ehlo nil)))) |
734 | 730 |
735 (smtpmail-try-auth-methods process supported-extensions host port) | 731 (smtpmail-try-auth-methods process supported-extensions host port) |
736 | 732 |
737 (if (or (member 'onex supported-extensions) | 733 (if (or (member 'onex supported-extensions) |
738 (member 'xone supported-extensions)) | 734 (member 'xone supported-extensions)) |
788 ;; 8BITMIME. | 784 ;; 8BITMIME. |
789 (if nil | 785 (if nil |
790 " BODY=8BITMIME" | 786 " BODY=8BITMIME" |
791 "") | 787 "") |
792 ""))) | 788 ""))) |
793 ; (smtpmail-send-command process (format "MAIL FROM:%s@%s" (user-login-name) (smtpmail-fqdn))) | 789 ;; (smtpmail-send-command process (format "MAIL FROM:%s@%s" (user-login-name) (smtpmail-fqdn))) |
794 (smtpmail-send-command process (format "MAIL FROM:<%s>%s%s" | 790 (smtpmail-send-command process (format "MAIL FROM:<%s>%s%s" |
795 envelope-from | 791 envelope-from |
796 size-part | 792 size-part |
797 body-part)) | 793 body-part)) |
798 | 794 |
799 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | 795 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
800 (not (integerp (car response-code))) | 796 (not (integerp (car response-code))) |
801 (>= (car response-code) 400)) | 797 (>= (car response-code) 400)) |
802 (throw 'done nil) | 798 (throw 'done nil))) |
803 )) | |
804 | 799 |
805 ;; RCPT TO:<recipient> | 800 ;; RCPT TO:<recipient> |
806 (let ((n 0)) | 801 (let ((n 0)) |
807 (while (not (null (nth n recipient))) | 802 (while (not (null (nth n recipient))) |
808 (smtpmail-send-command process (format "RCPT TO:<%s>" (smtpmail-maybe-append-domain (nth n recipient)))) | 803 (smtpmail-send-command process (format "RCPT TO:<%s>" (smtpmail-maybe-append-domain (nth n recipient)))) |
810 | 805 |
811 (setq response-code (smtpmail-read-response process)) | 806 (setq response-code (smtpmail-read-response process)) |
812 (if (or (null (car response-code)) | 807 (if (or (null (car response-code)) |
813 (not (integerp (car response-code))) | 808 (not (integerp (car response-code))) |
814 (>= (car response-code) 400)) | 809 (>= (car response-code) 400)) |
815 (throw 'done nil) | 810 (throw 'done nil)))) |
816 ) | |
817 )) | |
818 | 811 |
819 ;; DATA | 812 ;; DATA |
820 (smtpmail-send-command process "DATA") | 813 (smtpmail-send-command process "DATA") |
821 | 814 |
822 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | 815 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
823 (not (integerp (car response-code))) | 816 (not (integerp (car response-code))) |
824 (>= (car response-code) 400)) | 817 (>= (car response-code) 400)) |
825 (throw 'done nil) | 818 (throw 'done nil)) |
826 ) | |
827 | 819 |
828 ;; Mail contents | 820 ;; Mail contents |
829 (smtpmail-send-data process smtpmail-text-buffer) | 821 (smtpmail-send-data process smtpmail-text-buffer) |
830 | 822 |
831 ;;DATA end "." | 823 ;; DATA end "." |
832 (smtpmail-send-command process ".") | 824 (smtpmail-send-command process ".") |
833 | 825 |
834 (if (or (null (car (setq response-code (smtpmail-read-response process)))) | 826 (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
835 (not (integerp (car response-code))) | 827 (not (integerp (car response-code))) |
836 (>= (car response-code) 400)) | 828 (>= (car response-code) 400)) |
837 (throw 'done nil) | 829 (throw 'done nil)) |
838 ) | 830 |
839 | 831 ;; QUIT |
840 ;;QUIT | 832 ;; (smtpmail-send-command process "QUIT") |
841 ; (smtpmail-send-command process "QUIT") | 833 ;; (and (null (car (smtpmail-read-response process))) |
842 ; (and (null (car (smtpmail-read-response process))) | 834 ;; (throw 'done nil)) |
843 ; (throw 'done nil)) | 835 t)) |
844 t )) | |
845 (if process | 836 (if process |
846 (with-current-buffer (process-buffer process) | 837 (with-current-buffer (process-buffer process) |
847 (smtpmail-send-command process "QUIT") | 838 (smtpmail-send-command process "QUIT") |
848 (smtpmail-read-response process) | 839 (smtpmail-read-response process) |
849 | 840 |
850 ; (if (or (null (car (setq response-code (smtpmail-read-response process)))) | 841 ;; (if (or (null (car (setq response-code (smtpmail-read-response process)))) |
851 ; (not (integerp (car response-code))) | 842 ;; (not (integerp (car response-code))) |
852 ; (>= (car response-code) 400)) | 843 ;; (>= (car response-code) 400)) |
853 ; (throw 'done nil) | 844 ;; (throw 'done nil)) |
854 ; ) | |
855 (delete-process process) | 845 (delete-process process) |
856 (unless smtpmail-debug-info | 846 (unless smtpmail-debug-info |
857 (kill-buffer process-buffer))))))) | 847 (kill-buffer process-buffer))))))) |
858 | 848 |
859 | 849 |
937 (setq smtpmail-read-point (point)) | 927 (setq smtpmail-read-point (point)) |
938 ;; Escape "." at start of a line | 928 ;; Escape "." at start of a line |
939 (if (eq (string-to-char data) ?.) | 929 (if (eq (string-to-char data) ?.) |
940 (process-send-string process ".")) | 930 (process-send-string process ".")) |
941 (process-send-string process data) | 931 (process-send-string process data) |
942 (process-send-string process "\r\n") | 932 (process-send-string process "\r\n")) |
943 ) | |
944 | 933 |
945 (defun smtpmail-send-data (process buffer) | 934 (defun smtpmail-send-data (process buffer) |
946 (let ((data-continue t) sending-data) | 935 (let ((data-continue t) sending-data) |
947 (with-current-buffer buffer | 936 (with-current-buffer buffer |
948 (goto-char (point-min))) | 937 (goto-char (point-min))) |
956 (defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end) | 945 (defun smtpmail-deduce-address-list (smtpmail-text-buffer header-start header-end) |
957 "Get address list suitable for smtp RCPT TO: <address>." | 946 "Get address list suitable for smtp RCPT TO: <address>." |
958 (unwind-protect | 947 (unwind-protect |
959 (with-current-buffer smtpmail-address-buffer | 948 (with-current-buffer smtpmail-address-buffer |
960 (erase-buffer) | 949 (erase-buffer) |
961 (let | 950 (let ((case-fold-search t) |
962 ((case-fold-search t) | 951 (simple-address-list "") |
963 (simple-address-list "") | 952 this-line |
964 this-line | 953 this-line-end |
965 this-line-end | 954 addr-regexp) |
966 addr-regexp) | |
967 (insert-buffer-substring smtpmail-text-buffer header-start header-end) | 955 (insert-buffer-substring smtpmail-text-buffer header-start header-end) |
968 (goto-char (point-min)) | 956 (goto-char (point-min)) |
969 ;; RESENT-* fields should stop processing of regular fields. | 957 ;; RESENT-* fields should stop processing of regular fields. |
970 (save-excursion | 958 (save-excursion |
971 (setq addr-regexp | 959 (setq addr-regexp |
982 (while (and (looking-at "^[ \t]+") (< (point) header-end)) | 970 (while (and (looking-at "^[ \t]+") (< (point) header-end)) |
983 (forward-line 1)) | 971 (forward-line 1)) |
984 (setq this-line-end (point-marker)) | 972 (setq this-line-end (point-marker)) |
985 (setq simple-address-list | 973 (setq simple-address-list |
986 (concat simple-address-list " " | 974 (concat simple-address-list " " |
987 (mail-strip-quoted-names (buffer-substring this-line this-line-end)))) | 975 (mail-strip-quoted-names (buffer-substring this-line this-line-end))))) |
988 ) | |
989 (erase-buffer) | 976 (erase-buffer) |
990 (insert " " simple-address-list "\n") | 977 (insert " " simple-address-list "\n") |
991 (subst-char-in-region (point-min) (point-max) 10 ? t);; newline --> blank | 978 (subst-char-in-region (point-min) (point-max) 10 ? t) ; newline --> blank |
992 (subst-char-in-region (point-min) (point-max) ?, ? t);; comma --> blank | 979 (subst-char-in-region (point-min) (point-max) ?, ? t) ; comma --> blank |
993 (subst-char-in-region (point-min) (point-max) 9 ? t);; tab --> blank | 980 (subst-char-in-region (point-min) (point-max) 9 ? t) ; tab --> blank |
994 | 981 |
995 (goto-char (point-min)) | 982 (goto-char (point-min)) |
996 ;; tidyness in case hook is not robust when it looks at this | 983 ;; tidyness in case hook is not robust when it looks at this |
997 (while (re-search-forward "[ \t]+" header-end t) (replace-match " ")) | 984 (while (re-search-forward "[ \t]+" header-end t) (replace-match " ")) |
998 | 985 |
999 (goto-char (point-min)) | 986 (goto-char (point-min)) |
1000 (let (recipient-address-list) | 987 (let (recipient-address-list) |
1001 (while (re-search-forward " \\([^ ]+\\) " (point-max) t) | 988 (while (re-search-forward " \\([^ ]+\\) " (point-max) t) |
1002 (backward-char 1) | 989 (backward-char 1) |
1003 (setq recipient-address-list (cons (buffer-substring (match-beginning 1) (match-end 1)) | 990 (setq recipient-address-list (cons (buffer-substring (match-beginning 1) (match-end 1)) |
1004 recipient-address-list)) | 991 recipient-address-list))) |
1005 ) | 992 (setq smtpmail-recipient-address-list recipient-address-list)))))) |
1006 (setq smtpmail-recipient-address-list recipient-address-list)) | |
1007 | |
1008 ) | |
1009 ) | |
1010 ) | |
1011 ) | |
1012 | |
1013 | 993 |
1014 (defun smtpmail-do-bcc (header-end) | 994 (defun smtpmail-do-bcc (header-end) |
1015 "Delete [Resent-]BCC: and their continuation lines from the header area. | 995 "Delete [Resent-]BCC: and their continuation lines from the header area. |
1016 There may be multiple BCC: lines, and each may have arbitrarily | 996 There may be multiple BCC: lines, and each may have arbitrarily |
1017 many continuation lines." | 997 many continuation lines." |
1024 (progn (forward-line 1) (point))) | 1004 (progn (forward-line 1) (point))) |
1025 ;; get rid of any continuation lines | 1005 ;; get rid of any continuation lines |
1026 (while (and (looking-at "^[ \t].*\n") (< (point) header-end)) | 1006 (while (and (looking-at "^[ \t].*\n") (< (point) header-end)) |
1027 (replace-match "")))))) | 1007 (replace-match "")))))) |
1028 | 1008 |
1029 | |
1030 (provide 'smtpmail) | 1009 (provide 'smtpmail) |
1031 | 1010 |
1032 ;; arch-tag: a76992df-6d71-43b7-9e72-4bacc6c05466 | 1011 ;; arch-tag: a76992df-6d71-43b7-9e72-4bacc6c05466 |
1033 ;;; smtpmail.el ends here | 1012 ;;; smtpmail.el ends here |