]> code.delx.au - gnu-emacs/blob - lisp/mail/feedmail.el
Merge from emacs-24; up to 2012-12-30T19:34:25Z!jan.h.d@swipnet.se
[gnu-emacs] / lisp / mail / feedmail.el
1 ;;; feedmail.el --- assist other email packages to massage outgoing messages
2 ;;; This file is in the public domain.
3
4 ;; This file is part of GNU Emacs.
5
6 ;; Author: Bill Carpenter <bill@carpenter.ORG>
7 ;; Version: 11
8 ;; Keywords: email, queue, mail, sendmail, message, spray, smtp, draft
9 ;; X-URL: <URL:http://www.carpenter.org/feedmail/feedmail.html>
10
11 ;;; Commentary:
12
13 ;; A replacement for parts of sendmail.el (specifically,
14 ;; it's what handles your outgoing mail after you hit C-c C-c in mail
15 ;; mode). See below for a list of additional features, including the
16 ;; ability to queue messages for later sending. This replaces
17 ;; the standalone fakemail program that used to be distributed with Emacs.
18
19 ;; feedmail works with recent versions of Emacs (20.x series) and
20 ;; XEmacs (tested with 20.4 and later betas). It probably no longer
21 ;; works with Emacs v18, though I haven't tried that in a long
22 ;; time. Makoto.Nakagawa@jp.compaq.com reports: "I have a report
23 ;; that with a help of APEL library, feedmail works fine under emacs
24 ;; 19.28. You can get APEL from ftp://ftp.m17n.org/pub/mule/apel/.
25 ;; you need apel-10.2 or later to make feedmail work under emacs
26 ;; 19.28."
27
28 ;; Sorry, no manual yet in this release. Look for one with the next
29 ;; release. Or the one after that. Or maybe later.
30
31 ;; As far as I'm concerned, anyone can do anything they want with
32 ;; this specific piece of code. No warranty or promise of support is
33 ;; offered. This code is hereby released into the public domain.
34
35 ;; Thanks: My thanks to the many people who have sent me suggestions
36 ;; and fixes over time, as well as those who have tested many beta
37 ;; iterations. Some are cited in comments in code fragments below,
38 ;; but that doesn't correlate well with the list of folks who have
39 ;; actually helped me along the way.
40
41 ;; If you use feedmail, I invite you to send me some email about it.
42 ;; I appreciate feedback about problems you find or suggestions for
43 ;; improvements or added features (even though I can't predict when
44 ;; I'll incorporate changes). It's also OK with me if you send me a
45 ;; note along the lines of "I use feedmail and find it useful" or "I
46 ;; tried feedmail and didn't find it useful, so I stopped using it".
47 ;;
48 ;; It is most useful, when sending a bug report, if you tell me what
49 ;; version of Emacs you are using, what version of feedmail you are
50 ;; using, and what versions of other email-related elisp packages you
51 ;; are using. If in doubt about any of that, send the bug report
52 ;; anyhow.
53 ;;
54 ;; =====
55 ;; A NOTE TO THOSE WHO WOULD CHANGE THIS CODE... Since it is PD,
56 ;; you're within your rights to do whatever you want. If you do
57 ;; publish a new version with your changes in it, please (1) insert
58 ;; lisp comments describing the changes, (2) insert lisp comments
59 ;; that clearly delimit where your changes are, (3) email me a copy
60 ;; (I can't always consistently follow the relevant usenet groups),
61 ;; and (4) use a version number that is based on the version you're
62 ;; changing along with something that indicates you changed it. For
63 ;; example,
64 ;;
65 ;; (defconst feedmail-patch-level "123")
66 ;; (defconst feedmail-patch-level "123-XYZ-mods")
67 ;;
68 ;; The point of the last item, of course, is to try to minimize
69 ;; confusion. Odds are good that if your idea makes sense to me that
70 ;; it will show up in some future version of feedmail, though it's
71 ;; hard to say when releases will tumble out.
72 ;; =====
73 ;;
74 ;; This file requires the mail-utils library.
75 ;;
76 ;; This file requires the smtpmail library if you use
77 ;; feedmail-buffer-to-smtpmail. It requires the smtp library if
78 ;; you use feedmail-buffer-smtp.
79 ;;
80 ;; This file requires the custom library. Unfortunately, there are
81 ;; two incompatible versions of the custom library. If you don't have
82 ;; custom or you have the old version, this file will still load and
83 ;; work properly. If you don't know what custom is all about and want
84 ;; to edit your user option elisp variables the old fashioned way,
85 ;; just imagine that all the "defcustom" stuff you see below is really
86 ;; "defvar", and ignore everything else. For info about custom, see
87 ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>.
88 ;;
89 ;; This code does in elisp a superset of the stuff that used to be done
90 ;; by the separate program "fakemail" for processing outbound email.
91 ;; In other words, it takes over after you hit "C-c C-c" in mail mode.
92 ;; By appropriate setting of options, you can even revert to sendmail
93 ;; (which is not too popular locally). See the variables at the top
94 ;; of the elisp for how to achieve these effects (there are more
95 ;; features than in this bullet list, so trolling through the variable
96 ;; and function doc strings may be worth your while):
97 ;;
98 ;; --- you can park outgoing messages into a disk-based queue and
99 ;; stimulate sending them all later (handy for laptop users);
100 ;; there is also a queue for draft messages
101 ;;
102 ;; --- you can get one last look at the prepped outbound message and
103 ;; be prompted for confirmation
104 ;;
105 ;; --- removes Bcc:/Resent-Bcc: headers after getting address info
106 ;;
107 ;; --- does smart filling of address headers
108 ;;
109 ;; --- calls a routine to process Fcc: lines and removes them
110 ;;
111 ;; --- empty headers are removed
112 ;;
113 ;; --- can force From: or Sender: line
114 ;;
115 ;; --- can generate a Message-Id: line
116 ;;
117 ;; --- can generate a Date: line; the date can be the time the
118 ;; message was written or the time it is being sent
119 ;;
120 ;; --- strips comments from address info (both "()" and "<>" are
121 ;; handled via a call to mail-strip-quoted-names); the
122 ;; comments are stripped in the simplified address list given
123 ;; to a subprocess, not in the headers in the mail itself
124 ;; (they are left unchanged, modulo smart filling)
125 ;;
126 ;; --- error info is pumped into a normal buffer instead of the
127 ;; minibuffer
128 ;;
129 ;; --- just before the optional prompt for confirmation, lets you
130 ;; run a hook on the prepped message and simplified address
131 ;; list
132 ;;
133 ;; --- you can specify something other than /bin/mail for the
134 ;; subprocess
135 ;;
136 ;; --- you can generate/modify an X-Mailer: message header
137 ;;
138 ;; After a long list of options below, you will find the function
139 ;; feedmail-send-it. Hers's the best way to use the stuff in this
140 ;; file:
141 ;;
142 ;; Save this file as feedmail.el somewhere on your elisp loadpath;
143 ;; byte-compile it. Put the following lines in your init file:
144 ;;
145 ;; (setq send-mail-function 'feedmail-send-it)
146 ;; (autoload 'feedmail-send-it "feedmail")
147 ;;
148 ;; If you plan to use the queue stuff, also use this:
149 ;;
150 ;; (setq feedmail-enable-queue t)
151 ;; (autoload 'feedmail-run-the-queue "feedmail")
152 ;; (autoload 'feedmail-run-the-queue-no-prompts "feedmail")
153 ;; (setq auto-mode-alist (cons '("\\.fqm$" . mail-mode) auto-mode-alist))
154 ;;
155 ;; though VM users might find it more comfortable to use this instead of
156 ;; the above example's last line:
157 ;;
158 ;; (setq auto-mode-alist (cons '("\\.fqm$" . feedmail-vm-mail-mode) auto-mode-alist))
159 ;;
160 ;; If you end up getting asked about killing modified buffers all the time
161 ;; you are probably being prompted from outside feedmail. You can probably
162 ;; get cured by doing the defadvice stuff described in the documentation
163 ;; for the variable feedmail-queue-buffer-file-name below.
164 ;;
165 ;; If you are wondering how to send your messages to some SMTP server
166 ;; (which is not really a feedmail-specific issue), you are probably
167 ;; looking for smtpmail.el, and it is probably already present in your
168 ;; emacs installation. Look at smtpmail.el for how to set that up, and
169 ;; then do this to hook it into feedmail:
170 ;;
171 ;; (autoload 'feedmail-buffer-to-smtpmail "feedmail" nil t)
172 ;; (setq feedmail-buffer-eating-function 'feedmail-buffer-to-smtpmail)
173 ;;
174 ;; Alternatively, the FLIM <http://www.m17n.org/FLIM/> project
175 ;; provides a library called smtp.el. If you want to use that, the above lines
176 ;; would be:
177 ;;
178 ;; (autoload 'feedmail-buffer-to-smtp "feedmail" nil t)
179 ;; (setq feedmail-buffer-eating-function 'feedmail-buffer-to-smtp)
180 ;;
181 ;; If you are using the desktop.el library to restore your sessions, you might
182 ;; like to add the suffix ".fqm" to the list of non-saved things via the variable
183 ;; desktop-files-not-to-save.
184 ;;
185 ;; If you are planning to call feedmail-queue-reminder from your .emacs or
186 ;; something similar, you might need this:
187 ;;
188 ;; (autoload 'feedmail-queue-reminder "feedmail")
189 ;;
190 ;; If you ever use rmail-resend and queue messages, you should do this:
191 ;;
192 ;; (setq feedmail-queue-alternative-mail-header-separator "")
193 ;;
194 ;; If you want to automatically spell-check messages, but not when sending
195 ;; them from the queue, you could do something like this:
196 ;;
197 ;; (autoload 'feedmail-mail-send-hook-splitter "feedmail")
198 ;; (add-hook 'mail-send-hook 'feedmail-mail-send-hook-splitter)
199 ;; (add-hook 'feedmail-mail-send-hook 'ispell-message)
200 ;;
201 ;; If you are using message-mode to compose and send mail, feedmail will
202 ;; probably work fine with that (someone else tested it and told me it worked).
203 ;; Follow the directions above, but make these adjustments instead:
204 ;;
205 ;; (setq message-send-mail-function 'feedmail-send-it)
206 ;; (add-hook 'message-mail-send-hook 'feedmail-mail-send-hook-splitter)
207 ;;
208 ;; If you use message-mode and you make use of feedmail's queueing
209 ;; stuff, you might also like to adjust these variables to appropriate
210 ;; values for message-mode:
211 ;;
212 ;; feedmail-queue-runner-mode-setter
213 ;; feedmail-queue-runner-message-sender
214 ;;
215 ;; If you are using the "cmail" email package, there is some built-in
216 ;; support for feedmail in recent versions. To enable it, you should:
217 ;;
218 ;; (setq cmail-use-feedmail t)
219 ;;
220 ;;;;;;;;
221 ;;
222 ;; I think the LCD is no longer being updated, but if it were, this
223 ;; would be a proper LCD record. There is an old version of
224 ;; feedmail.el in the LCD archive. It works but is missing a lot of
225 ;; features.
226 ;;
227 ;; LCD record:
228 ;; feedmail|WJCarpenter|bill-feedmail@carpenter.ORG|Outbound mail queue handling|01-??-??|11-beta-??|feedmail.el
229 ;;
230 ;; Change log:
231 ;; original, 31 March 1991
232 ;; patchlevel 1, 5 April 1991
233 ;; patchlevel 2, 24 May 1991
234 ;; 5-may-92 jwz Conditionalized calling expand-mail-aliases, since that
235 ;; function doesn't exist in Lucid Emacs or when using
236 ;; mail-abbrevs.el.
237 ;; patchlevel 3, 3 October 1996
238 ;; added queue stuff; still works in v18
239 ;; patchlevel 4, issued by someone else
240 ;; patchlevel 5, issued by someone else
241 ;; patchlevel 6, not issued as far as I know
242 ;; patchlevel 7, 20 May 1997
243 ;; abandon futile support of Emacs 18 (sorry if that hurts you)
244 ;; provide a Date: header by default
245 ;; provide a default for generating Message-Id: header contents
246 ;; and use it by default (slightly changed API)
247 ;; return value from feedmail-run-the-queue
248 ;; new wrapper function feedmail-run-the-queue-no-prompts
249 ;; user-mail-address as default for From:
250 ;; properly deal with Resent-{To,Cc,Bcc}
251 ;; Bcc and Resent-* now included in smart filling
252 ;; limited support for a "drafts" directory
253 ;; user-configurable default message action
254 ;; allow timeout for confirmation prompt (where available)
255 ;; move Fcc handling to as late as possible to get max
256 ;; header munging in the saved file
257 ;; work around sendmail.el's prompts when working from queue
258 ;; more reliably detect voluntary user bailouts
259 ;; offer to save modified buffers visiting queue files
260 ;; offer to delete old file copies of messages being queued
261 ;; offer to delete queue files when sending immediately
262 ;; queue filename convention preserves queue order
263 ;; default queue and draft directory names that work on VMS
264 ;; deduced address list now really a list, not a string (API change)
265 ;; no more address buffer
266 ;; when sending immediately, brief reminder of queue/draft counts
267 ;; copy trace of smtpmail stuff to feedmail error buffer on no-go
268 ;; more granularity on when to confirm sending
269 ;; pause a bit for errors while running queue
270 ;; try to clean up some pesky auto-save files from the
271 ;; queue/draft directories
272 ;; feedmail-force-expand-mail-aliases in case you can't figure
273 ;; any other way
274 ;; cleanup some of my sloppiness about case-fold-search (a strange
275 ;; variable)
276 ;; best effort following coding conventions from Emacs
277 ;; elisp manual appendix
278 ;; "customize" (see custom.el)
279 ;; when user selects "immediate send", clear action prompt since
280 ;; hooks may take a while to operate, and user may think the
281 ;; response didn't take
282 ;; fixes to the argument conventions for the
283 ;; feedmail-queue-runner-* functions; allows
284 ;; feedmail-run-the-queue[-no-prompts] to properly be called
285 ;; non-interactively
286 ;; eliminate reliance on directory-sep-char and feedmail-sep-thing
287 ;; tweak smart filling (reminded of comma problem by levitte@lp.se)
288 ;; option to control writing in text vs binary mode
289 ;; patchlevel 8, 15 June 1998
290 ;; reliable re-editing of text-mode (vs binary) queued messages
291 ;; user option to keep Bcc: in Fcc: copy (keep by default)
292 ;; user option to delete body from Fcc: copy (keep by default)
293 ;; feedmail-deduce-bcc-where for envelope (API change for
294 ;; feedmail-deduce-address list)
295 ;; feedmail-queue-alternative-mail-header-separator
296 ;; at message action prompt, "I"/"S" bypass message confirmation prompt
297 ;; feedmail-mail-send-hook-splitter, feedmail-mail-send-hook,
298 ;; feedmail-mail-send-hook-queued
299 ;; user can supply stuff for message action prompt
300 ;; variable feedmail-queue-runner-confirm-global, function feedmail-run-the-queue-global-prompt
301 ;; bugfix: absolute argument to directory-files (tracked down for me
302 ;; by gray@austin.apc.slb.com (Douglas Gray Stephens)); relative
303 ;; pathnames can tickle stuff in ange-ftp remote directories
304 ;; (perhaps because feedmail is careless about its working
305 ;; directory)
306 ;; feedmail-deduce-envelope-from
307 ;; always supply envelope "from" (user-mail-address) to sendmail
308 ;; feedmail-message-id-suffix
309 ;; feedmail-queue-reminder, feedmail-queue-reminder-alist (after suggestions
310 ;; and/or code fragments from tonyl@Eng.Sun.COM (Tony Lam) and
311 ;; burge@newvision.com (Shane Burgess); bumped up the default value of
312 ;; feedmail-queue-chatty-sit-for since info is more complex sometimes
313 ;; feedmail-enable-spray (individual transmissions, crude mailmerge)
314 ;; blank Subject: no longer a special case; see feedmail-nuke-empty-headers
315 ;; fiddle-plexes data structure used lots of places; see feedmail-fiddle-plex-blurb
316 ;; feedmail-fiddle-plex-user-list
317 ;; feedmail-is-a-resend
318 ;; honor mail-from-style in constructing default for feedmail-from-line
319 ;; re-implement feedmail-from-line and feedmail-sender-line with
320 ;; fiddle-plexes; slightly modified semantics for feedmail-sender-line
321 ;; feedmail-queue-default-file-slug; tidy up some other slug details
322 ;; feedmail-queue-auto-file-nuke
323 ;; feedmail-queue-express-to-queue and feedmail-queue-express-to-draft
324 ;; strong versions of "q"ueue and "d"raft answers (always make a new file)
325 ;; patchlevel 9, 23 March 2001
326 ;; feedmail-queue-buffer-file-name to work around undesirable mail-send prompt
327 ;; at message action prompt, can scroll message buffer with "<" and ">";
328 ;; C-v no longer scrolls help buffer
329 ;; conditionalize (discard-input) in message action prompt to avoid killing
330 ;; define-kbd-macro
331 ;; fixed error if feedmail-x-mailer-line was nil
332 ;; feedmail-binmail-template only uses /bin/rmail if it exists
333 ;; relocate feedmail-queue-alternative-mail-header-separator stuff
334 ;; added feedmail-vm-mail-mode, which make a good auto-mode-alist entry
335 ;; for FQM files if you're a VM user
336 ;; change buffer-substring calls to buffer-substring-no-properties for
337 ;; speed-up (suggested by Howard Melman <howard@silverstream.com>)
338 ;; feedmail-sendmail-f-doesnt-sell-me-out to control "-f" in call to sendmail
339 ;; in feedmail-buffer-to-sendmail
340 ;; better trapping of odd conditions during the running of the queue;
341 ;; thanks to Yigal Hochberg for helping me test much of this by remote
342 ;; control
343 ;; feedmail-debug and feedmail-debug-sit-for
344 ;; feedmail-display-full-frame
345 ;; feedmail-queue-express-hook
346 ;; added example function feedmail-spray-via-bbdb
347 ;; use expand-file-name for setting default directory names
348 ;; define feedmail-binmail-gnulinuxish-template as a suggestion for
349 ;; the value of feedmail-binmail-template on GNU/Linux and maybe other
350 ;; systems with non-classic /bin/[r]mail behavior
351 ;; guard against nil user-mail-address in generating MESSAGE-ID:
352 ;; feedmail-queue-slug-suspect-regexp is now a variable to
353 ;; accommodate non-ASCII environments (thanks to
354 ;; Makoto.Nakagawa@jp.compaq.com for this suggestion)
355 ;; feedmail-buffer-to-smtp, to parallel feedmail-buffer-to-smtpmail
356 ;; patchlevel 10, 22 April 2001
357 ;; DATE: and MESSAGE-ID stuff now forces system-time-locale to "C"
358 ;; (brought to my attention by Makoto.Nakagawa@jp.compaq.com)
359 ;; patchlevel 11
360 ;; tweak default FROM: calculation to look at mail-host-address
361 ;; (suggested by "Jason Eisner" <jason@cs.jhu.edu>)
362 ;;
363 ;; todo:
364 ;; write texinfo manual
365 ;; maybe partition into multiple files, including files of examples
366 ;;
367 ;;; Code:
368
369 (defconst feedmail-patch-level "11-beta-1")
370
371 (require 'mail-utils) ; pick up mail-strip-quoted-names
372
373 (autoload 'mail-do-fcc "sendmail")
374
375 (defgroup feedmail nil
376 "Assist other email packages to massage outgoing messages."
377 :link '(url-link "http://www.carpenter.org/feedmail/feedmail.html")
378 :link '(emacs-commentary-link "feedmail")
379 :group 'mail)
380
381 (defgroup feedmail-misc nil
382 "Miscellaneous feedmail options that don't fit in other groups."
383 :group 'feedmail)
384
385 (defgroup feedmail-headers nil
386 "Options related to manipulating specific headers or types of headers."
387 :group 'feedmail)
388
389 (defgroup feedmail-queue nil
390 "Options related to queuing messages for later sending."
391 :group 'feedmail)
392
393 (defgroup feedmail-debug nil
394 "Options related to debug messages for later sending."
395 :group 'feedmail)
396
397
398 (defcustom feedmail-confirm-outgoing nil
399 "If non-nil, give a y-or-n confirmation prompt before sending mail.
400 This is done after the message is completely prepped, and you'll be
401 looking at the top of the message in a buffer when you get the prompt.
402 If set to the symbol 'queued, give the confirmation prompt only while
403 running the queue (however, the prompt is always suppressed if you are
404 processing the queue via `feedmail-run-the-queue-no-prompts'). If set
405 to the symbol 'immediate, give the confirmation prompt only when
406 sending immediately. For any other non-nil value, prompt in both
407 cases. You can give a timeout for the prompt; see variable
408 `feedmail-confirm-outgoing-timeout'."
409 :group 'feedmail-misc
410 :type 'boolean
411 )
412
413
414 (defcustom feedmail-display-full-frame 'queued
415 "If non-nil, show prepped messages in a full frame.
416 If nil, the prepped message will be shown, for confirmation or
417 otherwise, in some window in the current frame without resizing
418 anything. That may or may not display enough of the message to
419 distinguish it from others. If set to the symbol 'queued, take
420 this action only when running the queue. If set to the symbol
421 'immediate, take this action only when sending immediately. For
422 any other non-nil value, take the action in both cases. Even if
423 you're not confirming the sending of immediate or queued messages,
424 it can still be interesting to see a lot about them as they are
425 shuttled robotically onward."
426 :version "24.1"
427 :group 'feedmail-misc
428 :type 'boolean
429 )
430
431
432 (defcustom feedmail-confirm-outgoing-timeout nil
433 "If non-nil, a timeout in seconds at the send confirmation prompt.
434 If a positive number, it's a timeout before sending. If a negative
435 number, it's a timeout before not sending. This will not work if your
436 version of Emacs doesn't include the function `y-or-n-p-with-timeout'
437 \(e.g., some versions of XEmacs\)."
438 :version "24.1"
439 :group 'feedmail-misc
440 :type '(choice (const nil) integer)
441 )
442
443
444 (defcustom feedmail-nuke-bcc t
445 "If non-nil remove Bcc: lines from the message headers.
446 In any case, the Bcc: lines do participate in the composed address
447 list. You may want to leave them in if you're using sendmail
448 \(see `feedmail-buffer-eating-function'\)."
449 :group 'feedmail-headers
450 :type 'boolean
451 )
452
453
454 (defcustom feedmail-nuke-resent-bcc t
455 "If non-nil remove Resent-Bcc: lines from the message headers.
456 In any case, the Resent-Bcc: lines do participate in the composed
457 address list. You may want to leave them in if you're using sendmail
458 \(see `feedmail-buffer-eating-function'\)."
459 :group 'feedmail-headers
460 :type 'boolean
461 )
462
463
464 (defcustom feedmail-deduce-bcc-where nil
465 "Where Bcc:/Resent-Bcc: addresses should appear in the envelope list.
466 Addresses for the message envelope are deduced by examining
467 appropriate address headers in the message. Generally, they will show
468 up in the list of deduced addresses in the order that the headers
469 happen to appear (duplicate addresses are eliminated in any case).
470 This variable can be set to the symbol 'first, in which case the
471 Bcc:/Resent-Bcc: addresses will appear at the beginning in the list;
472 or, it can be set to the symbol 'last, in which case they will appear
473 at the end of the list.
474
475 Why should you care? Well, maybe you don't, and certainly the same
476 things could be accomplished by affecting the order of message headers
477 in the outgoing message. Some people use Bcc: as a way of getting
478 their own \"come back\" copy of each message they send. If Bcc:
479 addresses are not handled first, there can be substantial delays in
480 seeing the message again. Some configurations of sendmail, for example,
481 seem to try to deliver to each addressee at least once, immediately
482 and serially, so slow SMTP conversations can add up to a delay. There
483 is an option for either 'first or 'last because you might have a
484 delivery agent that processes the addresses backwards."
485 :group 'feedmail-headers
486 :type 'boolean
487 )
488
489
490 (defcustom feedmail-fill-to-cc t
491 "If non-nil do smart filling of addressee header lines.
492 Smart filling means breaking long lines at appropriate points and
493 making continuation lines. Despite the function name, it includes
494 To:, Cc:, Bcc: (and their Resent-* forms), as well as From: and
495 Reply-To: (though they seldom need it). If nil, the lines are left
496 as-is. The filling is done after mail address alias expansion."
497 :group 'feedmail-headers
498 :type 'boolean
499 )
500
501
502 (defcustom feedmail-fill-to-cc-fill-column default-fill-column
503 "Fill column used by `feedmail-fill-to-cc'."
504 :group 'feedmail-headers
505 :type 'integer
506 )
507
508
509 (defcustom feedmail-nuke-bcc-in-fcc nil
510 "If non-nil remove [Resent-]Bcc: lines in message copies saved via Fcc:.
511 This is independent of whether the Bcc: header lines are actually sent
512 with the message (see feedmail-nuke-bcc). Though not implied in the name,
513 the same Fcc: treatment applies to both Bcc: and Resent-Bcc: lines."
514 :group 'feedmail-headers
515 :type 'boolean
516 )
517
518
519 (defcustom feedmail-nuke-body-in-fcc nil
520 "If non-nil remove body of message in copies saved via Fcc:.
521 If a positive integer value, leave (up to) that many lines of the
522 beginning of the body intact. The result is that the Fcc: copy will
523 consist only of the message headers, serving as a sort of an outgoing
524 message log."
525 :group 'feedmail-headers
526 :type '(choice (const nil) (const t) integer)
527 )
528
529
530 (defcustom feedmail-force-expand-mail-aliases nil
531 "If non-nil, force the calling of `expand-mail-aliases'.
532 Normally, feedmail tries to figure out if you're using mailalias or
533 mailabbrevs and only calls `expand-mail-aliases' if it thinks you're
534 using the mailalias package. This user option can be used to force
535 the issue since there are configurations which fool the figuring
536 out."
537 :group 'feedmail-headers
538 :type 'boolean
539 )
540
541
542 (defcustom feedmail-nuke-empty-headers t
543 "If non-nil, remove header lines which have no contents.
544 A completely empty Subject: header is always removed, regardless of
545 the setting of this variable. The only time you would want them left
546 in would be if you used some headers whose presence indicated
547 something rather than their contents. This is rare in Internet email
548 but common in some proprietary systems."
549 :group 'feedmail-headers
550 :type 'boolean
551 )
552
553 ;; wjc sez: I think the use of the Sender: line is pretty pointless,
554 ;; but I left it in to be compatible with sendmail.el and because
555 ;; maybe some distant mail system needs it. Really, though, if you
556 ;; want a sender line in your mail, just put one in there and don't
557 ;; wait for feedmail to do it for you. (Yes, I know all about
558 ;; RFC-822 and RFC-1123, but are you *really* one of those cases
559 ;; they're talking about? I doubt it.)
560 (defcustom feedmail-sender-line nil
561 "If non-nil and the email has no Sender: header, use this value.
562 May be nil, in which case nothing in particular is done with respect
563 to Sender: lines. By design, will not replace an existing Sender:
564 line, but you can achieve that with a fiddle-plex 'replace action.
565 NB: it makes no sense to use the value t since there is no sensible
566 default for Sender:.
567
568 If not nil, it may be a string, a fiddle-plex, or a function which
569 returns either nil, t, a string, or a fiddle-plex (or, in fact,
570 another function, but let's not be ridiculous). If a string, it
571 should be just the contents of the header, not the name of the header
572 itself nor the trailing newline. If a function, it will be called
573 with no arguments. For an explanation of fiddle-plexes, see the
574 documentation for the variable `feedmail-fiddle-plex-blurb'. In all
575 cases the name element of the fiddle-plex is ignored and is hardwired
576 by feedmail to either \"Sender\" or \"Resent-Sender\".
577
578 You can probably leave this nil, but if you feel like using it, a good
579 value would be a string of a fully-qualified domain name form of your
580 address. For example, \"bill@example.net (WJCarpenter)\". The Sender:
581 header is fiddled after the From: header is fiddled."
582 :group 'feedmail-headers
583 :type '(choice (const nil) string)
584 )
585
586
587 (defcustom feedmail-force-binary-write t
588 "If non-nil, force writing file as binary (this applies to queues and Fcc:).
589 On systems where there is a difference between binary and text files,
590 feedmail will temporarily manipulate the value of `coding-system-for-write'
591 to make the writing as binary. If nil, writing will be in text mode.
592 On systems where there is no distinction or where it is controlled by other
593 variables or other means, this option has no effect."
594 :group 'feedmail-misc
595 :type 'boolean
596 )
597
598
599 (defcustom feedmail-from-line t
600 "If non-nil and the email has no From: header, use this value.
601 May be t, in which case a default is computed (and you probably won't
602 be happy with it). May be nil, in which case nothing in particular is
603 done with respect to From: lines. By design, will not replace an
604 existing From: line, but you can achieve that with a fiddle-plex 'replace
605 action.
606
607 If neither nil nor t, it may be a string, a fiddle-plex, or a function
608 which returns either nil, t, a string, or a fiddle-plex (or, in fact,
609 another function, but let's not be ridiculous). If a string, it
610 should be just the contents of the header, not the name of the header
611 itself nor the trailing newline. If a function, it will be called
612 with no arguments. For an explanation of fiddle-plexes, see the
613 documentation for the variable `feedmail-fiddle-plex-blurb'. In all
614 cases the name element of the fiddle-plex is ignored and is hardwired
615 by feedmail to either \"From\" or \"Resent-From\".
616
617 A good value would be a string fully-qualified domain name form of
618 your address. For example, \"bill@example.net (WJCarpenter)\". The
619 default value of this variable uses the standard elisp variable
620 `user-mail-address' which should be set on every system but has a decent
621 chance of being wrong. It also honors `mail-from-style'. Better to set
622 this variable explicitly to the string you want or find some other way
623 to arrange for the message to get a From: line."
624 :group 'feedmail-headers
625 :type '(choice (const t) (const nil) string)
626 )
627
628
629 (defcustom feedmail-sendmail-f-doesnt-sell-me-out nil
630 "Says whether the sendmail program issues a warning header if called with \"-f\".
631 The sendmail program has a useful feature to let you set the envelope FROM
632 address via a command line option, \"-f\". Unfortunately, it also has a widely
633 disliked default behavior of selling you out if you do that by inserting
634 an unattractive warning in the headers. It looks something like this:
635
636 X-Authentication-Warning: u1.example.com: niceguy set sender to niceguy@example.com using -f
637
638 It is possible to configure sendmail to not do this, but such a reconfiguration
639 is not an option for many users. As this is the default behavior of most
640 sendmail installations, one can mostly only wish it were otherwise. If feedmail
641 believes the sendmail program will sell you out this way, it won't use the \"-f\"
642 option when calling sendmail. If it doesn't think sendmail will sell you out,
643 it will use the \"-f\" \(since it is a handy feature\). You control what
644 feedmail thinks with this variable. The default is nil, meaning that feedmail
645 will believe that sendmail will sell you out."
646 :version "24.1"
647 :group 'feedmail-headers
648 :type 'boolean
649 )
650
651
652 (defcustom feedmail-deduce-envelope-from t
653 "If non-nil, deduce message envelope \"from\" from header From: or Sender:.
654 In other words, if there is a Sender: header in the message, temporarily
655 change the value of `user-mail-address' to be the same while the message
656 is being sent. If there is no Sender: header, use the From: header,
657 if any. Address values are taken from the actual message just before
658 it is sent, and the process is independent of the values of
659 `feedmail-from-line' and/or `feedmail-sender-line'.
660
661 There are many and good reasons for having the message header
662 From:/Sender: be different from the message envelope \"from\"
663 information. However, for most people and for most circumstances, it
664 is usual for them to be the same (this is probably especially true for
665 the case where the user doesn't understand the difference between the
666 two in the first place).
667
668 The idea behind this feature is that you can have everything set up
669 some normal way for yourself. If for some reason you want to send a
670 message with another From: line, you can just type it at the top of
671 the message, and feedmail will take care of \"fixing up\" the envelope
672 \"from\". This only works for mail senders which make use of
673 `user-mail-address' as the envelope \"from\" value. For some mail
674 senders (e.g., feedmail-buffer-to-bin-mail), there is no simple way to
675 influence what they will use as the envelope."
676 :group 'feedmail-headers
677 :type 'boolean
678 )
679
680
681 (defcustom feedmail-x-mailer-line-user-appendage nil
682 "See feedmail-x-mailer-line."
683 :group 'feedmail-headers
684 :type '(choice (const nil) (const t) string)
685 )
686
687
688 (defcustom feedmail-x-mailer-line t
689 "Control the form of an X-Mailer: header in an outgoing message.
690 Moderately useful for debugging, keeping track of your correspondents'
691 mailer preferences, or just wearing your MUA on your sleeve. You
692 should probably know that some people are fairly emotional about the
693 presence of X-Mailer: lines in email.
694
695 If nil, nothing is done about X-Mailer:.
696
697 If t, an X-Mailer: header of a predetermined format is produced,
698 combining its efforts with any existing X-Mailer: header. If you want
699 to take the default construct and just add a little blob of your own
700 at the end, define the variable feedmail-x-mailer-line-user-appendage
701 as that blob string. A value of t is equivalent to using the function
702 feedmail-default-x-mailer-generator.
703
704 If neither nil nor t, it may be a string, a fiddle-plex, or a function
705 which returns either nil, t, a string, or a fiddle-plex (or, in fact,
706 another function, but let's not be ridiculous). If a string, it
707 should be just the contents of the header, not the name of the header
708 itself nor the trailing newline. If a function, it will be called
709 with no arguments. For an explanation of fiddle-plexes, see the
710 documentation for the variable `feedmail-fiddle-plex-blurb'. In all
711 cases the name element of the fiddle-plex is ignored and is hardwired
712 by feedmail to either \"X-Mailer\" or \"X-Resent-Mailer\"."
713 :group 'feedmail-headers
714 :type '(choice (const t) (const nil) string function)
715 )
716
717
718 (defcustom feedmail-message-id-generator t
719 "Specifies the creation of a Message-Id: header field.
720
721 If nil, nothing is done about Message-Id:.
722
723 If t, a Message-Id: header of a predetermined format is produced, but
724 only if there is not already a Message-Id: in the message. A value of
725 t is equivalent to using the function feedmail-default-message-id-generator.
726
727 If neither nil nor t, it may be a string, a fiddle-plex, or a function
728 which returns either nil, t, a string, or a fiddle-plex (or, in fact,
729 another function, but let's not be ridiculous). If a string, it
730 should be just the contents of the header, not the name of the header
731 itself nor the trailing newline. If a function, it will be called
732 with one argument: the possibly-nil name of the file associated with
733 the message buffer. For an explanation of fiddle-plexes, see the
734 documentation for the variable `feedmail-fiddle-plex-blurb'. In all
735 cases the name element of the fiddle-plex is ignored and is hardwired
736 by feedmail to either \"Message-Id\" or \"Resent-Message-Id\".
737
738 You should let feedmail generate a Message-Id: for you unless you are sure
739 that whatever you give your messages to will do it for you (e.g., most
740 configurations of sendmail). Even if the latter case is true, it
741 probably won't hurt you to generate your own, and it will then show up
742 in the saved message if you use Fcc:."
743 :group 'feedmail-headers
744 :type '(choice (const t) (const nil) function)
745 )
746
747
748 (defcustom feedmail-message-id-suffix nil
749 "If non-nil, used as a suffix for generating unique Message-Id: headers.
750 The function `feedmail-default-message-id-generator' creates its work based
751 on a formatted date-time string, a random number, and a domain-looking suffix.
752 You can control the suffix used by assigning a string value to this variable.
753 If you don't supply one, the value of the variable `user-mail-address' will be
754 used. If the value of `feedmail-message-id-suffix' contains an \"@\" character,
755 the string will be used verbatim, else an \"@\" character will be prepended
756 automatically."
757 :group 'feedmail-headers
758 :type '(choice (const nil) string)
759 )
760
761 ;; this was suggested in various forms by several people; first was
762 ;; Tony DeSimone in Oct 1992; sorry to be so tardy
763 (defcustom feedmail-date-generator t
764 "Specifies the creation of a Date: header field.
765
766 If nil, nothing is done about Date:.
767
768 If t, a Date: header of a predetermined format is produced, but only
769 if there is not already a Date: in the message. A value of t is
770 equivalent to using the function `feedmail-default-date-generator'.
771
772 If neither nil nor t, it may be a string, a fiddle-plex, or a function
773 which returns either nil, t, a string, or a fiddle-plex (or, in fact,
774 another function, but let's not be ridiculous). If a string, it
775 should be just the contents of the header, not the name of the header
776 itself nor the trailing newline. If a function, it will be called
777 with one argument: the possibly-nil name of the file associated with
778 the message buffer. For an explanation of fiddle-plexes, see the
779 documentation for the variable `feedmail-fiddle-plex-blurb'. In all
780 cases the name element of the fiddle-plex is ignored and is hardwired
781 by feedmail to either \"Date\" or \"Resent-Date\".
782
783 If you decide to format your own date field, do us all a favor and know
784 what you're doing. Study the relevant parts of RFC-822 and RFC-1123.
785 Don't make me come up there!
786
787 You should let feedmail generate a Date: for you unless you are sure
788 that whatever you give your messages to will do it for you (e.g., most
789 configurations of sendmail). Even if the latter case is true, it
790 probably won't hurt you to generate your own, and it will then show up
791 in the saved message if you use Fcc:."
792 :group 'feedmail-headers
793 :type '(choice (const t) (const nil) function)
794 )
795
796
797 (defcustom feedmail-fiddle-headers-upwardly t
798 "Non-nil means fiddled header fields should go at the top of the header.
799 nil means insert them at the bottom. This is mostly a novelty issue since
800 the standards define the ordering of header fields to be immaterial and it's
801 fairly likely that some MTA/MUA along the way will have its own idea of what the
802 order should be, regardless of what you specify."
803 :group 'feedmail-headers
804 :type 'boolean
805 )
806
807
808 (defcustom feedmail-fiddle-plex-user-list nil
809 "If non-nil, should be a list of one or more fiddle-plexes.
810 Each element of the list can also be a function which returns a
811 fiddle-plex.
812
813 feedmail will use this list of fiddle-plexes to manipulate user-specified
814 message header fields. It does this after it has completed all normal
815 message header field manipulation and before calling `feedmail-last-chance-hook'.
816
817 For an explanation of fiddle-plexes, see the documentation for the
818 variable `feedmail-fiddle-plex-blurb'. In contrast to some other fiddle-plex
819 manipulation functions, in this context, it makes no sense to have an element
820 which is nil, t, or a simple string."
821 :group 'feedmail-headers
822 :type '(repeat (choice function)
823 sexp) ; too complex to be described accurately
824 )
825
826
827 (defcustom feedmail-enable-spray nil
828 "If non-nil, transmit message separately to each addressee.
829 feedmail normally accumulates a list of addressees and passes the message
830 along with that list to a buffer-eating function which expects any number
831 of addressees. If this variable is non-nil, however, feedmail will
832 repeatedly call the same buffer-eating function. Each time, the list of
833 addressees will be just one item from the original list. This only affects
834 the message envelope addresses and doesn't affect what appears in the
835 message headers except as noted.
836
837 Spray mode is usually pointless, and if you can't think of a good reason for
838 it, you should avoid it since it is inherently less efficient than normal
839 multiple delivery. One reason to use it is to overcome mis-featured mail
840 transports which betray your trust by revealing Bcc: addressees in the
841 headers of a message. Another use is to do a crude form of mailmerge, for
842 which see `feedmail-spray-address-fiddle-plex-list'.
843
844 If one of the calls to the buffer-eating function results in an error,
845 what happens next is carelessly defined, so beware. This should get ironed
846 out in some future release, and there could be other API changes for spraying
847 as well."
848 :group 'feedmail-spray
849 :type 'boolean
850 )
851
852 (defvar feedmail-spray-this-address nil
853 "Do not set this variable, except via `feedmail-spray-address-fiddle-plex-list'.")
854
855 (defcustom feedmail-spray-address-fiddle-plex-list nil
856 "User-supplied specification for a crude form of mailmerge capability.
857 When spraying is enabled, feedmail composes a list of envelope addresses.
858 In turn, `feedmail-spray-this-address' is temporarily set to each address
859 \(stripped of any comments and angle brackets\) and a function is called which
860 fiddles message headers according to this variable. See the documentation for
861 `feedmail-fiddle-plex-blurb', for an overview of fiddle-plex data structures.
862
863 May be nil, in which case nothing in particular is done about message
864 headers for specific addresses.
865
866 May be t, in which case a \"To:\" header is added to the message with
867 the stripped address as the header contents. The fiddle-plex operator
868 is 'supplement.
869
870 May be a string, in which case the string is assumed to be the name of
871 a message header field with the stripped address serving as the value.
872 The fiddle-plex operator is 'supplement.
873
874 May be a function, in which case it is called with no arguments and is
875 expected to return nil, t, a string, another function, or a fiddle-plex.
876 The result is used recursively. The function may alter the value of the
877 variable feedmail-spray-this-address, perhaps to embellish it with a
878 human name. It would be logical in such a case to return as a value a
879 string naming a message header like \"TO\" or an appropriately constructed
880 fiddle-plex. For an example, see feedmail-spray-via-bbdb.
881
882 May be a list of any combination of the foregoing and/or
883 fiddle-plexes. (A value for this variable which consists of a single
884 fiddle-plex must be nested inside another list to avoid ambiguity.)
885 If a list, each item is acted on in turn as described above.
886
887 For example,
888
889 (setq feedmail-spray-address-fiddle-plex-list 'feedmail-spray-via-bbdb)
890
891 The idea of the example is that, during spray mode, as each message is
892 about to be transmitted to an individual address, the function will be
893 called and will consult `feedmail-spray-this-address' to find the
894 stripped envelope email address (no comments or angle brackets). The
895 function should return an embellished form of the address.
896
897 The recipe for sending form letters is: (1) create a message with all
898 addressees on Bcc: headers; (2) tell feedmail to remove Bcc: headers
899 before sending the message; (3) create a function which will embellish
900 stripped addresses, if desired; (4) define `feedmail-spray-address-fiddle-plex-list'
901 appropriately; (5) send the message with `feedmail-enable-spray' set
902 non-nil; (6) stand back and watch co-workers wonder at how efficient
903 you are at accomplishing inherently inefficient things."
904 :group 'feedmail-spray
905 :type 'sexp ; too complex to be described accurately
906 )
907
908 ;; FIXME this is a macro?
909 (declare-function bbdb-search "ext:bbdb-com"
910 (records &optional name company net notes phone))
911 (declare-function bbdb-records "ext:bbdb"
912 (&optional dont-check-disk already-in-db-buffer))
913 (declare-function bbdb-dwim-net-address "ext:bbdb-com" (record &optional net))
914
915 (defun feedmail-spray-via-bbdb ()
916 "Example function for use with feedmail spray mode.
917 NB: it's up to the user to have the BBDB environment already set up properly
918 before using this."
919 (let (net-rec q-net-addy embellish)
920 (setq q-net-addy (concat "^" (regexp-quote feedmail-spray-this-address) "$"))
921 (setq net-rec (bbdb-search (bbdb-records) nil nil q-net-addy))
922 (if (and (car net-rec) (not (cdr net-rec)))
923 (setq net-rec (car net-rec))
924 (setq net-rec nil))
925 (if net-rec (setq embellish (bbdb-dwim-net-address net-rec)))
926 (if embellish
927 (list "To" embellish 'supplement)
928 (list "To" feedmail-spray-this-address 'supplement))))
929
930
931 (defcustom feedmail-enable-queue nil
932 "If non-nil, provide for stashing outgoing messages in a queue.
933 This is the master on/off switch for feedmail message queuing.
934 Queuing is quite handy for laptop-based users. It's also handy if you
935 get a lot of mail and process it more or less sequentially. For
936 example, you might change your mind about contents of a reply based on
937 a message you see a bit later.
938
939 There is a separate queue for draft messages, intended to prevent
940 you from accidentally sending incomplete messages. The queues are
941 disk-based and intended for later transmission. The messages are
942 queued in their raw state as they appear in the mail-mode buffer and
943 can be arbitrarily edited later, before sending, by visiting the
944 appropriate file in the queue directory (and setting the buffer to
945 mail-mode or whatever). If you visit a file in the queue directory
946 and try to queue it again, it will just get saved in its existing file
947 name. You can move a message from the draft to the main queue or vice
948 versa by pretending to send it and then selecting whichever queue
949 directory you want at the prompt. The right thing will happen.
950
951 To transmit all the messages in the queue, invoke the command
952 `feedmail-run-the-queue' or `feedmail-run-the-queue-no-prompts'."
953 :group 'feedmail-queue
954 :type 'boolean
955 )
956
957
958 (defcustom feedmail-queue-runner-confirm-global nil
959 "If non-nil, give a y-or-n confirmation prompt before running the queue.
960 Prompt even if the queue is about to be processed as a result of a call to
961 `feedmail-run-the-queue-no-prompts'. This gives you a way to bail out
962 without having to answer no to the individual message prompts."
963 :group 'feedmail-queue
964 :type 'boolean)
965
966
967 (defcustom feedmail-queue-directory
968 (expand-file-name "~/mail/q")
969 "Name of a directory where messages will be queued.
970 Directory will be created if necessary. Should be a string that
971 doesn't end with a slash. Default is \"~/mail/q\"."
972 :group 'feedmail-queue
973 :type 'string
974 )
975
976
977 (defcustom feedmail-queue-draft-directory
978 (expand-file-name "~/mail/draft")
979 "Name of a directory where draft messages will be queued.
980 Directory will be created if necessary. Should be a string that
981 doesn't end with a slash. Default is \"~/mail/draft\"."
982 :group 'feedmail-queue
983 :type 'string
984 )
985
986
987 (defcustom feedmail-ask-before-queue t
988 "If non-nil, feedmail will ask what you want to do with the message.
989 Default choices for the message action prompt will include sending it
990 immediately, putting it in the main queue, putting it in the draft
991 queue, or returning to the buffer to continue editing. Only matters if
992 queuing is enabled. If nil, the message is placed in the main queue
993 without a prompt."
994 :group 'feedmail-queue
995 :type 'boolean
996 )
997
998
999 (defcustom feedmail-ask-before-queue-prompt "FQM: Message action (q, i, d, e, ?)? [%s]: "
1000 "A string which will be used for the message action prompt.
1001 If it contains a \"%s\", that will be replaced with the value of
1002 `feedmail-ask-before-queue-default'."
1003 :group 'feedmail-queue
1004 :type 'string
1005 )
1006
1007
1008 (defcustom feedmail-ask-before-queue-reprompt "FQM: Please type q, i, d, or e; or ? for help [%s]: "
1009 "A string which will be used for reprompting after invalid input.
1010 If it contains a \"%s\", that will be replaced with the value of
1011 `feedmail-ask-before-queue-default'."
1012 :group 'feedmail-queue
1013 :type 'string
1014 )
1015
1016
1017 (defcustom feedmail-ask-before-queue-default "queue"
1018 "Meaning if user hits return in response to the message action prompt.
1019 Should be a character or a string; if a string, only the first
1020 character is significant. Useful values are those described in
1021 the help for the message action prompt."
1022 :group 'feedmail-queue
1023 :type '(choice string integer) ;use integer to get char
1024 )
1025
1026
1027 (defvar feedmail-prompt-before-queue-standard-alist
1028 '((?q . feedmail-message-action-queue)
1029 (?Q . feedmail-message-action-queue-strong)
1030
1031 (?d . feedmail-message-action-draft)
1032 (?r . feedmail-message-action-draft)
1033 (?D . feedmail-message-action-draft-strong)
1034 (?R . feedmail-message-action-draft-strong)
1035
1036 (?e . feedmail-message-action-edit)
1037 (?E . feedmail-message-action-edit)
1038 (?\C-g . feedmail-message-action-edit)
1039 (?n . feedmail-message-action-edit)
1040 (?N . feedmail-message-action-edit)
1041
1042 (?i . feedmail-message-action-send)
1043 (?I . feedmail-message-action-send-strong)
1044 (?s . feedmail-message-action-send)
1045 (?S . feedmail-message-action-send-strong)
1046
1047 (?* . feedmail-message-action-toggle-spray)
1048
1049 (?> . feedmail-message-action-scroll-up)
1050 (?< . feedmail-message-action-scroll-down)
1051 (? . feedmail-message-action-scroll-up)
1052 ;; (?\C-v . feedmail-message-action-help)
1053 (?? . feedmail-message-action-help))
1054 "An alist of choices for the message action prompt.
1055 All of the values are function names, except help, which is a special
1056 symbol that calls up help for the prompt (the help describes the
1057 actions from the standard alist). To customize your own choices,
1058 define a similar alist called `feedmail-prompt-before-queue-user-alist'.
1059 The actual alist used for message action will be the standard alist
1060 overlaid with the user-alist. To neutralize an item in the standard
1061 alist without providing a replacement, define an appropriate element
1062 in the user alist with a value of nil." )
1063
1064
1065 (defcustom feedmail-prompt-before-queue-user-alist nil
1066 "See `feedmail-prompt-before-queue-standard-alist'."
1067 :group 'feedmail-queue
1068 :type '(repeat (cons character function))
1069 )
1070
1071
1072 (defcustom feedmail-prompt-before-queue-help-supplement nil
1073 "User-provided supplementary help string for the message action prompt.
1074 When the message action prompt is shown, the user can as for verbose help,
1075 at which point a buffer pops up describing the meaning of possible
1076 responses to the prompt. Through various customizations (see, for
1077 example, `feedmail-prompt-before-queue-user-alist'), the available responses
1078 and the prompt itself can be changed. If this variable is set to a string
1079 value, that string is written to the help buffer after the standard info.
1080 It may contain embedded line breaks. It will be printed via `princ'."
1081 :group 'feedmail-queue
1082 :type '(choice (const nil) string)
1083 )
1084
1085
1086 (defcustom feedmail-queue-reminder-alist
1087 '((after-immediate . feedmail-queue-reminder-brief)
1088 (after-queue . feedmail-queue-reminder-medium)
1089 (after-draft . feedmail-queue-reminder-medium)
1090 (after-run . feedmail-queue-reminder-brief)
1091 (on-demand . feedmail-run-the-queue-global-prompt))
1092 "See `feedmail-queue-reminder'."
1093 :group 'feedmail-queue
1094 :type '(repeat (cons (choice :tag "Event"
1095 (const on-demand)
1096 (const after-immediate)
1097 (const after-queue)
1098 (const after-draft)
1099 (const after-run))
1100 function))
1101 )
1102
1103
1104 (defcustom feedmail-queue-chatty t
1105 "If non-nil, blat a few status messages and such in the mini-buffer.
1106 If nil, just do the work and don't pester people about what's going on.
1107 In some cases, though, specific options inspire mini-buffer prompting.
1108 That's not affected by this variable setting. Also does not control
1109 reporting of error/abnormal conditions."
1110 :group 'feedmail-queue
1111 :type 'boolean
1112 )
1113
1114
1115 (defcustom feedmail-queue-chatty-sit-for 2
1116 "Duration of pause after most queue-related messages.
1117 After some messages are divulged, it is prudent to pause before
1118 something else obliterates them. This value controls the duration of
1119 the pause."
1120 :group 'feedmail-queue
1121 :type 'integer
1122 )
1123
1124
1125 (defcustom feedmail-queue-run-orderer nil
1126 "If non-nil, name a function which will sort the queued messages.
1127 The function is called during a running of the queue for sending, and
1128 takes one argument, a list of the files in the queue directory. It
1129 may contain the names of non-message files, and it's okay to leave
1130 them in the list when reordering it; they get skipped over later.
1131 When nil, the default action processes the messages in normal sort
1132 order by queued file name, which will typically result in the order
1133 they were placed in the queue."
1134 :group 'feedmail-queue
1135 :type '(choice (const nil) function)
1136 )
1137
1138
1139 (defcustom feedmail-queue-use-send-time-for-date nil
1140 "If non-nil, use send time for the Date: header value.
1141 This variable is used by the default date generating function,
1142 feedmail-default-date-generator. If nil, the default, the
1143 last-modified timestamp of the queue file is used to create the
1144 message Date: header; if there is no queue file, the current time is
1145 used. If you are using VM, it might be supplying this header for
1146 you. To suppress VM's version
1147
1148 (setq vm-mail-header-insert-date nil)"
1149 :group 'feedmail-queue
1150 :type 'boolean
1151 )
1152
1153
1154 (defcustom feedmail-queue-use-send-time-for-message-id nil
1155 "If non-nil, use send time for the Message-Id: header value.
1156 This variable is used by the default Message-Id: generating function,
1157 `feedmail-default-message-id-generator'. If nil, the default, the
1158 last-modified timestamp of the queue file is used to create the
1159 message Message-Id: header; if there is no queue file, the current time is
1160 used. If you are using VM, it might be supplying this header for
1161 you. To suppress VM's version
1162
1163 (setq vm-mail-header-insert-date nil)"
1164 :group 'feedmail-queue
1165 :type 'boolean
1166 )
1167
1168
1169 (defcustom feedmail-ask-for-queue-slug nil
1170 "If non-nil, prompt user for part of the queue file name.
1171 The file will automatically get the FQM suffix and an embedded
1172 sequence number for uniqueness, so don't specify that. feedmail will
1173 get rid of all characters other than alphanumeric and hyphen in the
1174 results. If this variable is nil or if you just hit return in
1175 response to the prompt, feedmail queuing will take care of things
1176 properly. At the prompt, completion is available if you want to see
1177 what filenames are already in use, though, as noted, you will not be
1178 typing a complete file name. You probably don't want to be bothered
1179 with this prompting since feedmail, by default, uses queue file names
1180 based on the subjects of the messages."
1181 :group 'feedmail-queue
1182 :type 'boolean
1183 )
1184
1185
1186 (defcustom feedmail-queue-slug-maker 'feedmail-queue-subject-slug-maker
1187 "If non-nil, a function which creates part of the queued file name.
1188 Takes a single argument giving the name of the directory into
1189 which the message will be queued. The returned string should be just
1190 the non-directory filename part, without FQM suffix or uniquifying
1191 sequence numbers. The current buffer holds the raw message. The
1192 default function creates the slug based on the message subject, if
1193 any."
1194 :group 'feedmail-queue
1195 :type '(choice (const nil) function)
1196 )
1197
1198
1199 (defcustom feedmail-queue-slug-suspect-regexp "[^a-z0-9-]+"
1200 "Regular expression for characters/substrings to be replaced.
1201 When feedmail creates a filename from a subject string, it puts hyphens
1202 in place of strings which may cause problems in filenames. By default,
1203 only alphanumeric and hyphen characters are kept, and all others are
1204 converted. In non-ASCII environments, it may be more helpful to
1205 tweak this regular expression to reflect local or personal language
1206 conventions. Substitutions are done repeatedly until the regular expression
1207 no longer matches to transformed string. Used by function
1208 feedmail-tidy-up-slug and indirectly by feedmail-queue-subject-slug-maker."
1209 :version "24.1"
1210 :group 'feedmail-queue
1211 :type 'string
1212 )
1213
1214
1215 (defcustom feedmail-queue-default-file-slug t
1216 "Indicates what to use for subject-less messages when forming a file name.
1217 When feedmail queues a message, it creates a unique file name. By default,
1218 the file name is based in part on the subject of the message being queued.
1219 If there is no subject, consult this variable. See documentation for the
1220 function `feedmail-queue-subject-slug-maker'.
1221
1222 If t, an innocuous default is used.
1223
1224 If a string, it is used directly.
1225
1226 If a function, it is called with no arguments from the buffer containing the raw
1227 text of the message. It must return a string (which may be empty).
1228
1229 If the symbol 'ask, you will be prompted for a string in the mini-buffer.
1230 Filename completion is available so that you can inspect what's already been
1231 used, but feedmail will do further manipulation on the string you return, so
1232 it's not expected to be a complete filename."
1233 :group 'feedmail-queue
1234 :type '(choice (const :tag "Default" t) string function (const ask))
1235 )
1236
1237
1238 (defcustom feedmail-queue-fqm-suffix ".fqm"
1239 "The FQM suffix used to distinguish feedmail queued message files.
1240 You probably want this to be a period followed by some letters and/or
1241 digits. The distinction is to be able to tell them from other random
1242 files that happen to be in the `feedmail-queue-directory' or
1243 `feedmail-queue-draft-directory'. By the way, FQM stands for feedmail
1244 queued message."
1245 :group 'feedmail-queue
1246 :type 'string
1247 )
1248
1249
1250 (defcustom feedmail-nuke-buffer-after-queue nil
1251 "If non-nil, silently kill the buffer after a message is queued.
1252 You might like that since a side-effect of queueing the message is
1253 that its buffer name gets changed to the filename. That means that
1254 the buffer won't be reused for the next message you compose. If you
1255 are using VM for creating messages, you probably want to leave this
1256 nil, since VM has its own options for managing the recycling of
1257 message buffers."
1258 :group 'feedmail-queue
1259 :type 'boolean
1260 )
1261
1262
1263 (defcustom feedmail-queue-auto-file-nuke nil
1264 "If non-nil, automatically delete queue files when a message is sent.
1265 Normally, feedmail will notice such files when you send a message in
1266 immediate mode (i.e., not when you're running the queue) and will ask if
1267 you want to delete them. Since the answer is usually yes, setting this
1268 variable to non-nil will tell feedmail to skip the prompt and just delete
1269 the file without bothering you."
1270 :group 'feedmail-queue
1271 :type 'boolean
1272 )
1273
1274
1275 (defcustom feedmail-debug nil
1276 "If non-nil, blat a debug messages and such in the mini-buffer.
1277 This is intended as an aid to tracing what's going on but is probably
1278 of casual real use only to the feedmail developer."
1279 :version "24.1"
1280 :group 'feedmail-debug
1281 :type 'boolean
1282 )
1283
1284
1285 (defcustom feedmail-debug-sit-for 0
1286 "Duration of pause after feedmail-debug messages.
1287 After some messages are divulged, it may be helpful to pause before
1288 something else obliterates them. This value controls the duration of
1289 the pause. If the value is nil or 0, the sit-for is not done, which
1290 has the effect of not pausing at all. Debug messages can be seen after
1291 the fact in the messages buffer."
1292 :version "24.1"
1293 :group 'feedmail-debug
1294 :type 'integer
1295 )
1296
1297
1298 (defvar feedmail-queue-buffer-file-name nil
1299 "If non-nil, has the value normally expected of 'buffer-file-name'.
1300 You are not intended to set this to something in your configuration. Rather,
1301 you might programmatically set it to something via a hook or function
1302 advice or whatever. You might like to do this if you are using a mail
1303 composition program that eventually uses sendmail.el's 'mail-send'
1304 function to process the message. If there is a filename associated
1305 with the message buffer, 'mail-send' will ask you for confirmation.
1306 There's no trivial way to avoid it. It's unwise to just set the value
1307 of 'buffer-file-name' to nil because that will defeat feedmail's file
1308 management features. Instead, arrange for this variable to be set to
1309 the value of 'buffer-file-name' before setting that to nil. An easy way
1310 to do that would be with defadvice on 'mail-send' \(undoing the
1311 assignments in a later advice\).
1312
1313 feedmail will pretend that 'buffer-file-name', if nil, has the value
1314 assigned of 'feedmail-queue-buffer-file-name' and carry out its normal
1315 activities. feedmail does not restore the non-nil value of
1316 'buffer-file-name'. For safe bookkeeping, the user should insure that
1317 feedmail-queue-buffer-file-name is restored to nil.
1318
1319 Example 'defadvice' for mail-send:
1320
1321 (defadvice mail-send (before feedmail-mail-send-before-advice activate)
1322 (setq feedmail-queue-buffer-file-name buffer-file-name)
1323 (setq buffer-file-name nil))
1324
1325 (defadvice mail-send (after feedmail-mail-send-after-advice activate)
1326 (if feedmail-queue-buffer-file-name (setq buffer-file-name feedmail-queue-buffer-file-name))
1327 (setq feedmail-queue-buffer-file-name nil))
1328 ")
1329
1330 ;; defvars to make byte-compiler happy(er)
1331 (defvar feedmail-error-buffer nil)
1332 (defvar feedmail-prepped-text-buffer nil)
1333 (defvar feedmail-raw-text-buffer nil)
1334 (defvar feedmail-address-list nil)
1335
1336
1337 (defvar feedmail-queue-runner-is-active nil
1338 "Non-nil means we're inside the logic of the queue-running loop.
1339 That is, iterating over all messages in the queue to send them. In
1340 that case, the value is the name of the queued message file currently
1341 being processed. This can be used for differentiating customized code
1342 for different scenarios. Users shouldn't set or change this
1343 variable, but may depend on its value as described here.")
1344
1345
1346 (defun feedmail-mail-send-hook-splitter ()
1347 "Facilitate dividing `mail-send-hook' things into queued and immediate cases.
1348 If you have `mail-send-hook' functions that should only be called for sending/
1349 queueing messages or only be called for the sending of queued messages, this is
1350 for you. Add this function to `mail-send-hook' with something like this:
1351
1352 (add-hook 'mail-send-hook 'feedmail-mail-send-hook-splitter)
1353
1354 Then add the functions you want called to either `feedmail-mail-send-hook-queued'
1355 or `feedmail-mail-send-hook', as appropriate. The distinction is that
1356 `feedmail-mail-send-hook' will be called when you send mail from a composition
1357 buffer (typically by typing C-c C-c), whether the message is sent immediately
1358 or placed in the queue or drafts directory. `feedmail-mail-send-hook-queued' is
1359 called when messages are being sent from the queue directory, typically via a
1360 call to `feedmail-run-the-queue'."
1361 (feedmail-say-debug ">in-> feedmail-mail-send-hook-splitter %s" feedmail-queue-runner-is-active)
1362 (if feedmail-queue-runner-is-active
1363 (run-hooks 'feedmail-mail-send-hook-queued)
1364 (run-hooks 'feedmail-mail-send-hook)))
1365
1366 (defcustom feedmail-mail-send-hook nil
1367 "Hook run by `feedmail-mail-send-hook-splitter' for immediate mail.
1368 See documentation of `feedmail-mail-send-hook-splitter' for details."
1369 :type 'hook
1370 :group 'feedmail)
1371
1372 (defcustom feedmail-mail-send-hook-queued nil
1373 "Hook run by `feedmail-mail-send-hook-splitter' for queued mail.
1374 See documentation of `feedmail-mail-send-hook-splitter' for details."
1375 :type 'hook
1376 :group 'feedmail)
1377
1378 (defun feedmail-confirm-addresses-hook-example ()
1379 "An example of a `feedmail-last-chance-hook'.
1380 It shows the simple addresses and gets a confirmation. Use as:
1381 (setq feedmail-last-chance-hook 'feedmail-confirm-addresses-hook-example)."
1382 (save-window-excursion
1383 (display-buffer (set-buffer (get-buffer-create " F-C-A-H-E")))
1384 (erase-buffer)
1385 (insert (mapconcat 'identity feedmail-address-list " "))
1386 (if (not (y-or-n-p "How do you like them apples? "))
1387 (error "FQM: Sending...gave up in last chance hook"))))
1388
1389 (defcustom feedmail-last-chance-hook nil
1390 "User's last opportunity to modify the message on its way out.
1391 When this hook runs, the current buffer is already the appropriate
1392 buffer. It has already had all the header prepping from the standard
1393 package. The next step after running the hook will be to save the
1394 message via FCC: processing. The hook might be interested in these:
1395 \(1) `feedmail-prepped-text-buffer' contains the header and body of the
1396 message, ready to go; (2) `feedmail-address-list' contains a list
1397 of simplified recipients of addresses which are to be given to the
1398 subprocess (the hook may change the list); (3) `feedmail-error-buffer'
1399 is an empty buffer intended to soak up errors for display to the user.
1400 If the hook allows interactive activity, the user should not send more
1401 mail while in the hook since some of the internal buffers will be
1402 reused and things will get confused. It's not necessary to
1403 arrange for the undoing of any changes you make to the buffer."
1404 :group 'feedmail-misc
1405 :type 'hook
1406 )
1407
1408 (defcustom feedmail-queue-express-hook nil
1409 "Chance to modify a message being sent directly to a queue.
1410 Run by feedmail-queue-express-to-queue and feedmail-queue-express-to-draft.
1411 For example, you might want to run vm-mime-encode-composition to take
1412 care of attachments. If you subsequently edit the message buffer, you
1413 can undo the encoding."
1414 :version "24.1"
1415 :group 'feedmail-queue
1416 :type 'hook
1417 )
1418
1419 (defcustom feedmail-before-fcc-hook nil
1420 "User's last opportunity to modify the message before Fcc action.
1421 It has already had all the header prepping from the standard package.
1422 The next step after running the hook will be to save the message via
1423 Fcc: processing. The hook might be interested in these: (1)
1424 `feedmail-prepped-text-buffer' contains the header and body of the
1425 message, ready to go; (2) `feedmail-address-list' contains a list of
1426 simplified recipients of addressees to whom the message was sent (3)
1427 `feedmail-error-buffer' is an empty buffer intended to soak up errors
1428 for display to the user. If the hook allows interactive activity, the
1429 user should not send more mail while in the hook since some of the
1430 internal buffers will be reused and things will get confused."
1431 :group 'feedmail-misc
1432 :type 'hook
1433 )
1434
1435 (defcustom feedmail-queue-runner-mode-setter
1436 (lambda (&optional arg) (mail-mode))
1437 "A function to set the proper mode of a message file.
1438 Called when the message is read back out of the queue directory with a single
1439 argument, the optional argument used in the call to
1440 `feedmail-run-the-queue' or `feedmail-run-the-queue-no-prompts'.
1441
1442 Most people want `mail-mode', so the default value is an anonymous
1443 function which is just a wrapper to ignore the supplied argument when
1444 calling it, but here's your chance to have something different.
1445 If you are a VM user, you might like feedmail-vm-mail-mode, though you
1446 really don't need that (and it's not particularly well-tested).
1447
1448 Called with funcall, not `call-interactively'."
1449 :group 'feedmail-queue
1450 :type 'function
1451 )
1452
1453
1454 (defcustom feedmail-queue-alternative-mail-header-separator nil
1455 "Alternative header demarcation for queued messages.
1456 If you sometimes get alternative values for `mail-header-separator' in
1457 queued messages, set the value of this variable to whatever it is.
1458 For example, `rmail-resend' uses a `mail-header-separator' value of empty
1459 string (\"\") when you send/queue a message.
1460
1461 When trying to send a queued message, if the value of this variable is
1462 non-nil, feedmail will first try to send the message using the value
1463 of `mail-header-separator'. If it can't find that, it will temporarily
1464 set `mail-header-separator' to the value of
1465 `feedmail-queue-alternative-mail-header-separator' and try again."
1466 :group 'feedmail-queue
1467 :type '(choice (const nil) string)
1468 )
1469
1470
1471 (defcustom feedmail-queue-runner-message-sender
1472 (lambda (&optional arg) (mail-send))
1473 "Function to initiate sending a message file.
1474 Called for each message read back out of the queue directory with a
1475 single argument, the optional argument used in the call to
1476 `feedmail-run-the-queue' or `feedmail-run-the-queue-no-prompts'.
1477 Interactively, that argument will be the prefix argument.
1478 Most people want `mail-send' (bound to C-c C-s in mail-mode), but here's
1479 your chance to have something different. The default value is just a
1480 wrapper function which discards the optional argument and calls
1481 mail-send. If you are a VM user, you might like vm-mail-send, though
1482 you really don't need that. Called with funcall, not call-interactively."
1483 :version "24.1" ; changed default
1484 :group 'feedmail-queue
1485 :type 'function
1486 )
1487
1488
1489 (defcustom feedmail-queue-runner-cleaner-upper
1490 (lambda (fqm-file &optional arg)
1491 (delete-file fqm-file)
1492 (if arg (feedmail-say-chatter "Nuked %s" fqm-file)))
1493 "Function that will be called after a message has been sent.
1494 Not called in the case of errors. This function is called with two
1495 arguments: the name of the message queue file for the message just sent,
1496 and the optional argument used in the call to `feedmail-run-the-queue'
1497 or `feedmail-run-the-queue-no-prompts' (prefix arg if interactive).
1498 In any case, the affiliated buffer is killed elsewhere, so don't do that
1499 inside this function. Return value is ignored.
1500
1501 The default action is an anonymous function which gets rid of the file
1502 from the queue directory. With a non-nil second argument, a brief
1503 message is give for each file deleted. You could replace this
1504 function, for example, to archive all of your sent messages someplace
1505 \(though there are better ways to get that particular result\)."
1506 :group 'feedmail-queue
1507 :type 'function
1508 )
1509
1510
1511 (defvar feedmail-is-a-resend nil
1512 "Non-nil means the message is a Resend (in the RFC-822 sense).
1513 This affects the composition of certain headers. feedmail sets this
1514 variable as soon as it starts prepping the message text buffer, so any
1515 user-supplied functions can rely on it. Users shouldn't set or change this
1516 variable, but may depend on its value as described here.")
1517
1518
1519 (defcustom feedmail-buffer-eating-function 'feedmail-buffer-to-binmail
1520 "Function used to send the prepped buffer to a subprocess.
1521 The function's three (mandatory) arguments are: (1) the buffer
1522 containing the prepped message; (2) a buffer where errors should be
1523 directed; and (3) a list containing the addresses individually as
1524 strings. Popular choices for this are `feedmail-buffer-to-binmail',
1525 `feedmail-buffer-to-smtpmail', `feedmail-buffer-to-sendmail', and
1526 `feedmail-buffer-to-smtp'. If you use the sendmail form, you probably
1527 want to set `feedmail-nuke-bcc' and/or `feedmail-nuke-resent-bcc to nil'.
1528 If you use the binmail form, check the value of `feedmail-binmail-template'."
1529 :group 'feedmail-misc
1530 :type 'function
1531 )
1532
1533 (defconst feedmail-binmail-gnulinuxish-template
1534 (concat
1535 "(echo From "
1536 (if (boundp 'user-login-name) user-login-name "feedmail")
1537 " ; cat -) | /usr/bin/rmail %s")
1538 "Good candidate for GNU/Linux systems and maybe others.
1539 You may need to modify this if your \"rmail\" is in a different place.
1540 For example, I hear that in some Debian systems, it's /usr/sbin/rmail.
1541 See feedmail-binmail-template documentation."
1542 )
1543
1544 (defcustom feedmail-binmail-template (if mail-interactive "/bin/mail %s"
1545 (if (file-exists-p "/bin/rmail")
1546 "/bin/rmail %s" "/bin/mail %s"))
1547 "Command template for the subprocess which will get rid of the mail.
1548 It can result in any command understandable by /bin/sh. Might not
1549 work at all in non-UNIX environments. The single '%s', if present,
1550 gets replaced by the space-separated, simplified list of addressees.
1551 Used in `feedmail-buffer-to-binmail' to form the shell command which
1552 will receive the contents of the prepped buffer as stdin. The default
1553 value uses /bin/rmail (if it exists) unless `mail-interactive' has been
1554 set non-nil.
1555
1556 If you'd like your errors to come back as mail instead of immediately
1557 in a buffer, try /bin/rmail instead of /bin/mail. If /bin/rmail
1558 exists, this can be accomplished by keeping the default nil setting of
1559 `mail-interactive'. You might also like to consult local mail experts
1560 for any other interesting command line possibilities. Some versions
1561 of UNIX have an rmail program which behaves differently than
1562 /bin/rmail and complains if feedmail gives it a message on stdin. If
1563 you don't know about such things and if there is no local expert to
1564 consult, stick with /bin/mail or use one of the other buffer eating
1565 functions.
1566
1567 The above description applies to \"classic\" UNIX /bin/mail and /bin/rmail.
1568 On most GNU/Linux systems and perhaps other places, /bin/mail behaves
1569 completely differently and shouldn't be used at all in this template.
1570 Instead of /bin/rmail, there is a /usr/bin/rmail, and it can be used
1571 with a wrapper. The wrapper is necessary because /usr/bin/rmail on such
1572 systems requires that the first line of the message appearing on standard
1573 input have a UNIX-style From_ postmark. If you have such a system, the
1574 wrapping can be accomplished by setting the value of `feedmail-binmail-template'
1575 to `feedmail-binmail-gnulinuxish-template'. You should then send some test
1576 messages to make sure it works as expected."
1577 :version "24.1" ; changed default
1578 :group 'feedmail-misc
1579 :type 'string
1580 )
1581
1582
1583 ;; feedmail-buffer-to-binmail, feedmail-buffer-to-sendmail, and
1584 ;; feedmail-buffer-to-smtpmail are the only things provided for values
1585 ;; for the variable feedmail-buffer-eating-function. It's pretty easy
1586 ;; to write your own, though.
1587 (defun feedmail-buffer-to-binmail (prepped errors-to addr-listoid)
1588 "Function which actually calls /bin/mail as a subprocess.
1589 Feeds the buffer to it."
1590 (feedmail-say-debug ">in-> feedmail-buffer-to-binmail %s" addr-listoid)
1591 (set-buffer prepped)
1592 (apply
1593 'call-process-region
1594 (append (list (point-min) (point-max) "/bin/sh" nil errors-to nil "-c"
1595 (format feedmail-binmail-template
1596 (mapconcat 'identity addr-listoid " "))))))
1597
1598
1599 (defvar sendmail-program)
1600
1601 (defun feedmail-buffer-to-sendmail (prepped errors-to addr-listoid)
1602 "Function which actually calls sendmail as a subprocess.
1603 Feeds the buffer to it. Probably has some flaws for Resent-* and other
1604 complicated cases. Takes addresses from message headers and
1605 might disappoint you with BCC: handling. In case of odd results, consult
1606 local gurus."
1607 (require 'sendmail)
1608 (feedmail-say-debug ">in-> feedmail-buffer-to-sendmail %s" addr-listoid)
1609 (set-buffer prepped)
1610 (apply 'call-process-region
1611 (append (list (point-min) (point-max) sendmail-program
1612 nil errors-to nil "-oi" "-t")
1613 ;; provide envelope "from" to sendmail; results will vary
1614 (if feedmail-sendmail-f-doesnt-sell-me-out
1615 (list "-f" user-mail-address))
1616 ;; These mean "report errors by mail" and "deliver in background".
1617 (if (null mail-interactive) '("-oem" "-odb")))))
1618
1619 (declare-function smtpmail-via-smtp "smtpmail"
1620 (recipient smtpmail-text-buffer &optional ask-for-password))
1621 (defvar smtpmail-smtp-server)
1622
1623 ;; provided by jam@austin.asc.slb.com (James A. McLaughlin);
1624 ;; simplified by WJC after more feedmail development;
1625 ;; idea (but not implementation) of copying smtpmail trace buffer to
1626 ;; feedmail error buffer from:
1627 ;; Mon 14-Oct-1996; Douglas Gray Stephens
1628 ;; modified to insert error for displaying
1629 (defun feedmail-buffer-to-smtpmail (prepped errors-to addr-listoid)
1630 "Function which actually calls `smtpmail-via-smtp' to send buffer as e-mail."
1631 ;; I'm not sure smtpmail.el is careful about the following
1632 ;; return value, but it also uses it internally, so I will fear
1633 ;; no evil.
1634 (feedmail-say-debug ">in-> feedmail-buffer-to-smtpmail %s" addr-listoid)
1635 (require 'smtpmail)
1636 (let ((result (smtpmail-via-smtp addr-listoid prepped)))
1637 (when result
1638 (set-buffer errors-to)
1639 (insert "Send via smtpmail failed: %s" result)
1640 (let ((case-fold-search t)
1641 ;; don't be overconfident about the name of the trace buffer
1642 (tracer (concat "trace.*smtp.*" (regexp-quote smtpmail-smtp-server))))
1643 (mapcar
1644 (lambda (buffy)
1645 (if (string-match tracer (buffer-name buffy))
1646 (progn
1647 (insert "SMTP Trace from " (buffer-name buffy) "\n---------------")
1648 (insert-buffer-substring buffy)
1649 (insert "\n\n"))))
1650 (buffer-list))))))
1651
1652 (declare-function smtp-via-smtp "ext:smtp" (sender recipients smtp-text-buffer))
1653 (defvar smtp-server)
1654
1655 ;; FLIM's smtp.el pointed out to me by Kenichi Handa <handa@etl.go.jp>
1656 (defun feedmail-buffer-to-smtp (prepped errors-to addr-listoid)
1657 "Function which actually calls smtp-via-smtp to send buffer as e-mail."
1658 (feedmail-say-debug ">in-> feedmail-buffer-to-smtp %s" addr-listoid)
1659 (require 'smtp)
1660 (if (not (smtp-via-smtp user-mail-address addr-listoid prepped))
1661 (progn
1662 (set-buffer errors-to)
1663 (insert "Send via smtp failed. Probable SMTP protocol error.\n")
1664 (insert "Look for details below or in the *Messages* buffer.\n\n")
1665 (let ((case-fold-search t)
1666 ;; don't be overconfident about the name of the trace buffer
1667 (tracer (concat "trace.*smtp.*" (regexp-quote smtp-server))))
1668 (mapcar
1669 (lambda (buffy)
1670 (if (string-match tracer (buffer-name buffy))
1671 (progn
1672 (insert "SMTP Trace from " (buffer-name buffy) "\n---------------")
1673 (insert-buffer-substring buffy)
1674 (insert "\n\n"))))
1675 (buffer-list))))))
1676
1677 ;; just a place to park a docstring
1678 (defconst feedmail-fiddle-plex-blurb nil
1679 "A fiddle-plex is a concise way of specifying header field fiddling.
1680 It is a list of up to 4 elements: NAME, VALUE, ACTION, FOLDING. The element
1681 VALUE can also be a list sometimes.
1682
1683 NAME is the name of the header field to be fiddled with. Although case
1684 doesn't matter in looking for headers, case of NAME is preserved when a header
1685 is inserted via fiddling. It shouldn't include the trailing colon.
1686
1687 VALUE is either nil, a simple string, a function returning nil or a string, or,
1688 as described below for ACTION `combine', a list of up to three values.
1689
1690 ACTION describes the nature of the fiddling to be done. Possibilities
1691 for ACTION (default is `supplement'):
1692
1693 `supplement' Leave other like fields as-is, insert this one.
1694
1695 `replace' Delete other like fields, if any, and insert this one.
1696
1697 `create' Insert this one only if no like field exists.
1698
1699 `combine' Combine aggregate values of like fields with this one.
1700 In this case, VALUE has a special form. It is a list
1701 of three items: VAL-PRE, VAL-LIKE, and VAL-POST.
1702 VAL-PRE and VAL-POST are strings or nil. VAL-LIKE may
1703 be either a string or a function (it may also be nil,
1704 but there's not much point to that).
1705
1706 Values of like header fields are aggregated, leading and
1707 trailing whitespace is removed, and embedded
1708 whitespace is left as-is. If there are no like
1709 fields, or the aggregate value is an empty string,
1710 VAL-LIKE is not used. Else, if VAL-LIKE is a function,
1711 it is called with two arguments: NAME and the
1712 aggregate like values. Else, if VAL-LIKE is a string, it is
1713 used as a format string where a single \%s will be
1714 replaced by the aggregate values of like fields.
1715
1716 VAL-PRE, the results of using VAL-LIKE, and VAL-POST
1717 are concatenated, and the result, if not nil and not
1718 an empty string, is used as the new value for the
1719 field. Although this description sounds a bit
1720 complicated, the idea is to provide a mechanism for
1721 combining the old value with a new value in a flexible
1722 way. For example, if you wanted to add a new value to
1723 an existing header field by adding a semi-colon and
1724 then starting the new value on a continuation line,
1725 you might specify this:
1726
1727 (nil \"%s;\\n\\t\" \"This is my new value\")
1728
1729 FOLDING can be nil, in which case VALUE is used as-is. If FOLDING is
1730 non-nil, feedmail \"smart filling\" is done on VALUE just before
1731 insertion.")
1732
1733 (declare-function vm-mail "ext:vm" (&optional to subject))
1734
1735 (defun feedmail-vm-mail-mode (&optional arg)
1736 "Make something like a buffer that has been created via `vm-mail'.
1737 The optional argument is ignored and is just for argument compatibility with
1738 `feedmail-queue-runner-mode-setter'. This function is suitable for being
1739 applied to a file after you've just read it from disk: for example, a
1740 feedmail FQM message file from a queue. You could use something like
1741 this:
1742
1743 \(setq auto-mode-alist \(cons \'\(\"\\\\.fqm$\" . feedmail-vm-mail-mode\) auto-mode-alist\)\)
1744 "
1745 (feedmail-say-debug ">in-> feedmail-vm-mail-mode")
1746 (let ((the-buf (current-buffer)))
1747 (vm-mail)
1748 (delete-region (point-min) (point-max))
1749 (insert-buffer-substring the-buf)
1750 (setq buffer-file-name (buffer-file-name the-buf))
1751 (set-buffer-modified-p (buffer-modified-p the-buf))
1752 ;; For some versions of emacs, saving the message to a queue
1753 ;; triggers running the mode function on the buffer, and that
1754 ;; leads (through a series of events I don't really understand)
1755 ;; to this function being called while the buffer is still
1756 ;; marked modified even though it is in the process of being
1757 ;; saved. I guess the function gets called during the renaming
1758 ;; that takes place en route to the save.
1759 ;;
1760 ;; This clearing of the marker probably wastes a buffer copy
1761 ;; but it's easy to do and more reliable than figuring out what
1762 ;; each variant of emacs does in this strange case.
1763 (with-current-buffer the-buf
1764 (set-buffer-modified-p nil))
1765 (kill-buffer the-buf)
1766 ))
1767
1768 ;;;###autoload
1769 (defun feedmail-send-it ()
1770 "Send the current mail buffer using the Feedmail package.
1771 This is a suitable value for `send-mail-function'. It can be used
1772 with various lower-level mechanisms to provide features such as queueing."
1773 (feedmail-say-debug ">in-> feedmail-send-it")
1774 (save-excursion
1775 (let ((bfn-jiggle nil))
1776 ;; if buffer-file-name is nil, temporarily use the stashed value
1777 (if (and (not buffer-file-name) feedmail-queue-buffer-file-name)
1778 (setq buffer-file-name feedmail-queue-buffer-file-name
1779 bfn-jiggle t))
1780 ;; avoid matching trouble over slash vs backslash by getting canonical
1781 (if feedmail-queue-directory
1782 (setq feedmail-queue-directory (expand-file-name feedmail-queue-directory)))
1783 (if feedmail-queue-draft-directory
1784 (setq feedmail-queue-draft-directory (expand-file-name feedmail-queue-draft-directory)))
1785 (if (not feedmail-enable-queue) (feedmail-send-it-immediately-wrapper)
1786 ;; else, queuing is enabled, should we ask about it or just do it?
1787 (if feedmail-ask-before-queue
1788 (funcall (feedmail-queue-send-edit-prompt))
1789 (feedmail-dump-message-to-queue feedmail-queue-directory 'after-queue)))
1790 ;; put this back
1791 (if bfn-jiggle (setq feedmail-queue-buffer-file-name buffer-file-name))
1792 )))
1793
1794 (defun feedmail-message-action-send ()
1795 ;; hooks can make this take a while so clear the prompt
1796 (feedmail-say-debug ">in-> feedmail-message-action-send")
1797 (message "FQM: Immediate send...")
1798 (feedmail-send-it-immediately-wrapper))
1799
1800
1801 ;; From a VM mailing list discussion and some suggestions from Samuel Mikes <smikes@alumni.hmc.edu>
1802 (defun feedmail-queue-express-to-queue ()
1803 "Send message directly to the queue, with a minimum of fuss and bother."
1804 (interactive)
1805 (feedmail-say-debug ">in-> feedmail-queue-express-to-queue")
1806 (run-hooks 'feedmail-queue-express-hook)
1807 (let ((feedmail-enable-queue t)
1808 (feedmail-ask-before-queue nil)
1809 (feedmail-queue-reminder-alist nil)
1810 (feedmail-queue-chatty-sit-for 0))
1811 (feedmail-send-it)
1812 )
1813 )
1814
1815
1816 (defun feedmail-queue-express-to-draft ()
1817 "Send message directly to the draft queue, with a minimum of fuss and bother."
1818 (interactive)
1819 (feedmail-say-debug ">in-> feedmail-queue-express-to-draft")
1820 (let ((feedmail-queue-directory feedmail-queue-draft-directory))
1821 (feedmail-queue-express-to-queue)
1822 )
1823 )
1824
1825
1826 (defun feedmail-message-action-send-strong ()
1827 (feedmail-say-debug ">in-> feedmail-message-action-send-strong")
1828 (let ((feedmail-confirm-outgoing nil)) (feedmail-message-action-send)))
1829
1830
1831 (defun feedmail-message-action-edit ()
1832 (feedmail-say-debug ">in-> feedmail-message-action-edit")
1833 (error "FQM: Message not queued; returning to edit"))
1834
1835
1836 (defun feedmail-message-action-draft ()
1837 (feedmail-say-debug ">in-> feedmail-message-action-draft")
1838 (feedmail-dump-message-to-queue feedmail-queue-draft-directory 'after-draft))
1839
1840
1841 (defun feedmail-message-action-draft-strong ()
1842 (feedmail-say-debug ">in-> feedmail-message-action-draft-strong")
1843 (let ((buffer-file-name nil))
1844 (feedmail-message-action-draft)))
1845
1846
1847 (defun feedmail-message-action-queue ()
1848 (feedmail-say-debug ">in-> feedmail-message-action-queue")
1849 (feedmail-dump-message-to-queue feedmail-queue-directory 'after-queue))
1850
1851
1852 (defun feedmail-message-action-queue-strong ()
1853 (feedmail-say-debug ">in-> feedmail-message-action-queue-strong")
1854 (let ((buffer-file-name nil))
1855 (feedmail-message-action-queue)))
1856
1857
1858 (defun feedmail-message-action-toggle-spray ()
1859 (feedmail-say-debug ">in-> feedmail-message-action-toggle-spray")
1860 (let ((feedmail-enable-spray (not feedmail-enable-spray)))
1861 (if feedmail-enable-spray
1862 (message "FQM: For this message, spray toggled ON")
1863 (message "FQM: For this message, spray toggled OFF"))
1864 (sit-for 3)
1865 ;; recursion, but harmless
1866 (feedmail-send-it)))
1867
1868
1869 (defconst feedmail-p-h-b-n "*FQM Help*")
1870
1871 (defun feedmail-message-action-help ()
1872 (feedmail-say-debug ">in-> feedmail-message-action-help")
1873 (let ((d-string " ")
1874 (fqm-help (get-buffer feedmail-p-h-b-n)))
1875 (if (stringp feedmail-ask-before-queue-default)
1876 (setq d-string feedmail-ask-before-queue-default)
1877 (setq d-string (char-to-string feedmail-ask-before-queue-default)))
1878 (if (and fqm-help (get-buffer-window fqm-help))
1879 (feedmail-scroll-buffer 'up fqm-help)
1880 (feedmail-message-action-help-blat d-string))
1881 ;; recursive, but no worries (it goes deeper on user action)
1882 (feedmail-send-it)))
1883
1884 (defun feedmail-message-action-help-blat (d-string)
1885 (feedmail-say-debug ">in-> feedmail-message-action-help-blat")
1886 (with-output-to-temp-buffer feedmail-p-h-b-n
1887 (princ "You're dispatching a message and feedmail queuing is enabled.
1888 Typing ? again will normally scroll this help buffer.
1889
1890 Choices:
1891 q QUEUE for later sending \(via feedmail-run-the-queue\)
1892 Q QUEUE! like \"q\", but always make a new file
1893 i IMMEDIATELY send this \(but not the other queued messages\)
1894 I IMMEDIATELY! like \"i\", but skip following confirmation prompt
1895 d DRAFT queue in the draft directory
1896 D DRAFT! like \"d\", but always make a new file
1897 e EDIT return to the message edit buffer \(don't send or queue\)
1898 * SPRAY toggle spray mode \(individual message transmissions\)
1899 > SCROLL UP scroll message up \(toward end of message\)
1900 < SCROLL DOWN scroll message down \(toward beginning of message\)
1901 ? HELP show or scroll this help buffer
1902
1903 Synonyms:
1904 s SEND immediately \(same as \"i\"\)
1905 S SEND! immediately \(same as \"I\"\)
1906 r ROUGH draft \(same as \"d\"\)
1907 R ROUGH! draft \(same as \"D\"\)
1908 n NOPE didn't mean it \(same as \"e\"\)
1909 y YUP do the default behavior \(same as \"C-m\"\)
1910 SPC SCROLL UP \(same as \">\"\)
1911
1912 The user-configurable default is currently \"")
1913 (princ d-string)
1914 (princ "\". For other possibilities,
1915 see the variable feedmail-prompt-before-queue-user-alist.
1916 ")
1917 (and (stringp feedmail-prompt-before-queue-help-supplement)
1918 (princ feedmail-prompt-before-queue-help-supplement))
1919 (with-current-buffer standard-output
1920 (if (fboundp 'help-mode) (help-mode)))))
1921
1922
1923 (defun feedmail-message-action-scroll-up ()
1924 (feedmail-say-debug ">in-> feedmail-message-action-scroll-up")
1925 (feedmail-scroll-buffer 'up)
1926 ;; recursive, but no worries (it goes deeper on user action)
1927 (feedmail-send-it))
1928
1929
1930 (defun feedmail-message-action-scroll-down ()
1931 (feedmail-say-debug ">in-> feedmail-message-action-scroll-down")
1932 (feedmail-scroll-buffer 'down)
1933 ;; recursive, but no worries (it goes deeper on user action)
1934 (feedmail-send-it))
1935
1936
1937 ;;;###autoload
1938 (defun feedmail-run-the-queue-no-prompts (&optional arg)
1939 "Like `feedmail-run-the-queue', but suppress confirmation prompts."
1940 (interactive "p")
1941 (feedmail-say-debug ">in-> feedmail-run-the-queue-no-prompts")
1942 (let ((feedmail-confirm-outgoing nil)) (feedmail-run-the-queue arg)))
1943
1944 ;;;###autoload
1945 (defun feedmail-run-the-queue-global-prompt (&optional arg)
1946 "Like `feedmail-run-the-queue', but with a global confirmation prompt.
1947 This is generally most useful if run non-interactively, since you can
1948 bail out with an appropriate answer to the global confirmation prompt."
1949 (interactive "p")
1950 (feedmail-say-debug ">in-> feedmail-run-the-queue-global-prompts")
1951 (let ((feedmail-queue-runner-confirm-global t)) (feedmail-run-the-queue arg)))
1952
1953 ;;;###autoload
1954 (defun feedmail-run-the-queue (&optional arg)
1955 "Visit each message in the feedmail queue directory and send it out.
1956 Return value is a list of three things: number of messages sent, number of
1957 messages skipped, and number of non-message things in the queue (commonly
1958 backup file names and the like)."
1959 (interactive "p")
1960 (feedmail-say-debug ">in-> feedmail-run-the-queue")
1961 ;; avoid matching trouble over slash vs backslash by getting canonical
1962 (if feedmail-queue-directory
1963 (setq feedmail-queue-directory (expand-file-name feedmail-queue-directory)))
1964 (if feedmail-queue-draft-directory
1965 (setq feedmail-queue-draft-directory (expand-file-name feedmail-queue-draft-directory)))
1966 (let* ((maybe-file)
1967 (qlist (feedmail-look-at-queue-directory feedmail-queue-directory))
1968 (dlist (feedmail-look-at-queue-directory feedmail-queue-draft-directory))
1969 (q-cnt (nth 0 qlist))
1970 (q-oth (nth 1 qlist))
1971 (d-cnt (nth 0 dlist))
1972 (d-oth (nth 1 dlist))
1973 (messages-sent 0)
1974 (messages-skipped 0)
1975 (blobby-buffer)
1976 (already-buffer)
1977 (do-the-run t)
1978 (list-of-possible-fqms))
1979 (if (and (> q-cnt 0) feedmail-queue-runner-confirm-global)
1980 (setq do-the-run
1981 (if (fboundp 'y-or-n-p-with-timeout)
1982 (y-or-n-p-with-timeout (format "FQM: Draft: %dm+%d, Queue: %dm+%d; run the queue? "
1983 d-cnt d-oth q-cnt q-oth)
1984 5 nil)
1985 (y-or-n-p (format "FQM: Draft: %dm+%d, Queue: %dm+%d; run the queue? "
1986 d-cnt d-oth q-cnt q-oth))
1987 )))
1988 (if (not do-the-run)
1989 (setq messages-skipped q-cnt)
1990 (save-window-excursion
1991 (setq list-of-possible-fqms (directory-files feedmail-queue-directory t))
1992 (if feedmail-queue-run-orderer
1993 (setq list-of-possible-fqms (funcall feedmail-queue-run-orderer list-of-possible-fqms)))
1994 (mapc
1995 (lambda (blobby)
1996 (setq maybe-file (expand-file-name blobby feedmail-queue-directory))
1997 (cond
1998 ((file-directory-p maybe-file) nil) ; don't care about subdirs
1999 ((feedmail-fqm-p blobby)
2000 (setq blobby-buffer (generate-new-buffer (concat "FQM " blobby)))
2001 (setq already-buffer
2002 (if (fboundp 'find-buffer-visiting) ; missing from XEmacs
2003 (find-buffer-visiting maybe-file)
2004 (get-file-buffer maybe-file)))
2005 (if (and already-buffer (buffer-modified-p already-buffer))
2006 (save-window-excursion
2007 (display-buffer (set-buffer already-buffer))
2008 (if (fboundp 'y-or-n-p-with-timeout)
2009 ;; make a guess that the user just forgot to save
2010 (if (y-or-n-p-with-timeout (format "FQM: Visiting %s; save before send? " blobby) 10 t)
2011 (save-buffer))
2012 (if (y-or-n-p (format "FQM: Visiting %s; save before send? " blobby))
2013 (save-buffer))
2014 )))
2015
2016 (set-buffer blobby-buffer)
2017 (setq buffer-offer-save nil)
2018 (buffer-disable-undo blobby-buffer)
2019 (insert-file-contents-literally maybe-file)
2020 (goto-char (point-min))
2021 ;; if at least two line-endings with CRLF, translate the file
2022 (if (looking-at ".*\r\n.*\r\n")
2023 (while (search-forward "\r\n" nil t)
2024 (replace-match "\n" nil t)))
2025 (funcall feedmail-queue-runner-mode-setter arg)
2026 (condition-case signal-stuff ; don't give up the loop if user skips some
2027 (let ((feedmail-enable-queue nil)
2028 (feedmail-queue-runner-is-active maybe-file))
2029 ;; if can't find EOH, this is no message!
2030 (unless (feedmail-find-eoh t)
2031 (feedmail-say-chatter "Skipping %s; no mail-header-separator" maybe-file)
2032 (error "FQM: you should never see this message"))
2033 (feedmail-say-debug "Prepping %s" maybe-file)
2034 ;; the catch is a way out for users to voluntarily skip sending a message
2035 (catch 'skip-me-q (funcall feedmail-queue-runner-message-sender arg))
2036 (set-buffer blobby-buffer)
2037 (if (buffer-modified-p) ; still modified, means wasn't sent
2038 (progn
2039 (setq messages-skipped (1+ messages-skipped))
2040 (feedmail-say-chatter "%s wasn't sent by %s" maybe-file feedmail-buffer-eating-function))
2041 (setq messages-sent (1+ messages-sent))
2042 (funcall feedmail-queue-runner-cleaner-upper maybe-file arg)
2043 (if (and already-buffer (not (file-exists-p maybe-file)))
2044 ;; we have gotten rid of the file associated with the
2045 ;; buffer, so update the buffer's notion of that
2046 (with-current-buffer already-buffer
2047 (setq buffer-file-name nil)))))
2048 ;; the handler for the condition-case
2049 (error (setq messages-skipped (1+ messages-skipped))
2050 (ding t)
2051 (message "FQM: Trapped '%s', message left in queue." (car signal-stuff))
2052 (sit-for 3)
2053 (message "FQM: Trap details: \"%s\""
2054 (mapconcat 'identity (cdr signal-stuff) "\" \""))
2055 (sit-for 3)))
2056 (kill-buffer blobby-buffer)
2057 (feedmail-say-chatter
2058 "%d to go, %d sent, %d skipped (%d other files ignored)"
2059 (- q-cnt messages-sent messages-skipped)
2060 messages-sent messages-skipped q-oth)
2061 )))
2062 list-of-possible-fqms)))
2063 (if feedmail-queue-chatty
2064 (progn
2065 (feedmail-say-chatter "%d sent, %d skipped (%d other files ignored)"
2066 messages-sent messages-skipped q-oth)
2067 (feedmail-queue-reminder 'after-run)
2068 (sit-for feedmail-queue-chatty-sit-for)))
2069 (list messages-sent messages-skipped q-oth)))
2070
2071
2072 ;;;###autoload
2073 (defun feedmail-queue-reminder (&optional what-event)
2074 "Perform some kind of reminder activity about queued and draft messages.
2075 Called with an optional symbol argument which says what kind of event
2076 is triggering the reminder activity. The default is 'on-demand, which
2077 is what you typically would use if you were putting this in your Emacs start-up
2078 or mail hook code. Other recognized values for WHAT-EVENT (these are passed
2079 internally by feedmail):
2080
2081 after-immediate (a message has just been sent in immediate mode)
2082 after-queue (a message has just been queued)
2083 after-draft (a message has just been placed in the draft directory)
2084 after-run (the queue has just been run, possibly sending messages)
2085
2086 WHAT-EVENT is used as a key into the table `feedmail-queue-reminder-alist'. If
2087 the associated value is a function, it is called without arguments and is expected
2088 to perform the reminder activity. You can supply your own reminder functions
2089 by redefining `feedmail-queue-reminder-alist'. If you don't want any reminders,
2090 you can set `feedmail-queue-reminder-alist' to nil."
2091 (interactive "p")
2092 (feedmail-say-debug ">in-> feedmail-queue-reminder %s" what-event)
2093 (let ((key (if (and what-event (symbolp what-event)) what-event 'on-demand)) entry reminder)
2094 (setq entry (assoc key feedmail-queue-reminder-alist))
2095 (setq reminder (cdr entry))
2096 (if (fboundp reminder) (funcall reminder)))
2097 )
2098
2099
2100 (defun feedmail-queue-reminder-brief ()
2101 "Brief display of draft and queued message counts in minibuffer."
2102 (interactive)
2103 (feedmail-say-debug ">in-> feedmail-queue-reminder-brief")
2104 (let (q-cnt d-cnt q-lis d-lis)
2105 (setq q-lis (feedmail-look-at-queue-directory feedmail-queue-directory))
2106 (setq d-lis (feedmail-look-at-queue-directory feedmail-queue-draft-directory))
2107 (setq q-cnt (car q-lis))
2108 (setq d-cnt (car d-lis))
2109 (if (or (> q-cnt 0) (> d-cnt 0))
2110 (progn
2111 (message "FQM: [D: %d, Q: %d]" d-cnt q-cnt))))
2112 )
2113
2114
2115 (defun feedmail-queue-reminder-medium ()
2116 "Verbose display of draft and queued message counts in minibuffer."
2117 (interactive)
2118 (feedmail-say-debug ">in-> feedmail-queue-reminder-medium")
2119 (let (q-cnt d-cnt q-oth d-oth q-lis d-lis)
2120 (setq q-lis (feedmail-look-at-queue-directory feedmail-queue-directory))
2121 (setq d-lis (feedmail-look-at-queue-directory feedmail-queue-draft-directory))
2122 (setq q-cnt (car q-lis))
2123 (setq d-cnt (car d-lis))
2124 (setq q-oth (nth 1 q-lis))
2125 (setq d-oth (nth 1 d-lis))
2126 (if (or (> q-cnt 0) (> d-cnt 0))
2127 (progn
2128 (message "FQM: Draft: %dm+%d in \"%s\", Queue: %dm+%d in \"%s\""
2129 d-cnt d-oth (file-name-nondirectory feedmail-queue-draft-directory)
2130 q-cnt q-oth (file-name-nondirectory feedmail-queue-directory)))))
2131 )
2132
2133
2134 (defun feedmail-queue-send-edit-prompt ()
2135 "Ask whether to queue, send immediately, or return to editing a message, etc."
2136 (feedmail-say-debug ">in-> feedmail-queue-send-edit-prompt")
2137 (feedmail-queue-send-edit-prompt-inner
2138 feedmail-ask-before-queue-default
2139 feedmail-ask-before-queue-prompt
2140 feedmail-ask-before-queue-reprompt
2141 'feedmail-message-action-help
2142 feedmail-prompt-before-queue-standard-alist
2143 feedmail-prompt-before-queue-user-alist
2144 ))
2145
2146 (defun feedmail-queue-runner-prompt ()
2147 "Ask whether to queue, send immediately, or return to editing a message, etc."
2148 (feedmail-say-debug ">in-> feedmail-queue-runner-prompt")
2149 (feedmail-queue-send-edit-prompt-inner
2150 feedmail-ask-before-queue-default
2151 feedmail-ask-before-queue-prompt
2152 feedmail-ask-before-queue-reprompt
2153 'feedmail-message-action-help
2154 feedmail-prompt-before-queue-standard-alist
2155 feedmail-prompt-before-queue-user-alist
2156 ))
2157 (defun feedmail-queue-send-edit-prompt-inner (default prompt reprompt helper
2158 standard-alist user-alist)
2159 (feedmail-say-debug ">in-> feedmail-queue-send-edit-prompt-inner")
2160 ;; Some implementation ideas here came from the userlock.el code
2161 (or defining-kbd-macro (discard-input))
2162 (save-window-excursion
2163 (let ((answer) (d-char) (d-string " "))
2164 (if (stringp default)
2165 (progn
2166 (setq d-char (string-to-char default)
2167 d-string default))
2168 (setq d-string (char-to-string default))
2169 (setq d-char default)
2170 )
2171 (while (null answer)
2172 (message prompt d-string)
2173 (let ((user-sez
2174 (let ((inhibit-quit t) (cursor-in-echo-area t) (echo-keystrokes 0))
2175 (read-char-exclusive))))
2176 (if (= user-sez help-char)
2177 (setq answer '(^ . helper))
2178 (if (or (eq user-sez ?\C-m) (eq user-sez ?\C-j) (eq user-sez ?y))
2179 (setq user-sez d-char))
2180 ;; these char-to-int things are because of some
2181 ;; incomprehensible difference between the two in
2182 ;; byte-compiled stuff between Emacs and XEmacs
2183 ;; (well, I'm sure someone could comprehend it,
2184 ;; but I say 'uncle')
2185 (setq answer (or (assoc user-sez user-alist)
2186 (and (fboundp 'char-to-int)
2187 (assoc (char-to-int user-sez) user-alist))
2188 (assoc user-sez standard-alist)
2189 (and (fboundp 'char-to-int)
2190 (assoc (char-to-int user-sez) standard-alist))))
2191 (if (or (null answer) (null (cdr answer)))
2192 (progn
2193 (beep)
2194 (message reprompt d-string)
2195 (sit-for 3)))
2196 )))
2197 (cdr answer)
2198 )))
2199
2200 (defun feedmail-scroll-buffer (direction &optional buffy)
2201 ;; scrolling fun
2202 ;; emacs convention is that scroll-up moves text up, window down
2203 (feedmail-say-debug ">in-> feedmail-scroll-buffer %s" direction)
2204 (save-selected-window
2205 (let ((signal-error-on-buffer-boundary nil)
2206 (fqm-window (display-buffer (if buffy buffy (current-buffer)))))
2207 (select-window fqm-window)
2208 (if (eq direction 'up)
2209 (if (pos-visible-in-window-p (point-max) fqm-window)
2210 ;; originally just (goto-char (point-min)), but
2211 ;; pos-visible-in-window-p seems oblivious to that
2212 (scroll-down 999999)
2213 (scroll-up))
2214 (if (pos-visible-in-window-p (point-min) fqm-window)
2215 (scroll-up 999999)
2216 (scroll-down))))))
2217
2218
2219 (defun feedmail-look-at-queue-directory (queue-directory)
2220 "Find out some things about a queue directory.
2221 Result is a list containing a count of queued messages in the
2222 directory, a count of other files in the directory, and a high water
2223 mark for prefix sequence numbers. Subdirectories are not included in
2224 the counts."
2225 (feedmail-say-debug ">in-> feedmail-look-at-queue-directory %s" queue-directory)
2226 (let ((q-cnt 0) (q-oth 0) (high-water 0) (blobbet))
2227 ;; iterate, counting things we find along the way in the directory
2228 (if (file-directory-p queue-directory)
2229 (mapc
2230 (lambda (blobby)
2231 (cond
2232 ((file-directory-p blobby) nil) ; don't care about subdirs
2233 ((feedmail-fqm-p blobby)
2234 (setq blobbet (file-name-nondirectory blobby))
2235 (if (string-match "^[0-9][0-9][0-9]-" blobbet)
2236 (let ((water-mark))
2237 (setq water-mark (string-to-number (substring blobbet 0 3)))
2238 (if (> water-mark high-water) (setq high-water water-mark))))
2239 (setq q-cnt (1+ q-cnt)))
2240 (t (setq q-oth (1+ q-oth)))
2241 ))
2242 (directory-files queue-directory t)))
2243 (list q-cnt q-oth high-water)))
2244
2245 (defun feedmail-tidy-up-slug (slug)
2246 "Utility for mapping out suspect characters in a potential filename."
2247 (feedmail-say-debug ">in-> feedmail-tidy-up-slug %s" slug)
2248 ;; even programmers deserve a break sometimes, so cover nil for them
2249 (if (null slug) (setq slug ""))
2250 ;; replace all non-alphanumerics with hyphen for safety
2251 (while (string-match feedmail-queue-slug-suspect-regexp slug) (setq slug (replace-match "-" nil nil slug)))
2252 ;; collapse multiple hyphens to one
2253 (while (string-match "--+" slug) (setq slug (replace-match "-" nil nil slug)))
2254 ;; for tidiness, peel off leading hyphens
2255 (if (string-match "^-*" slug) (setq slug (replace-match "" nil nil slug)))
2256 ;; for tidiness, peel off trailing hyphens
2257 (if (string-match "-*$" slug) (setq slug (replace-match "" nil nil slug)))
2258 slug
2259 )
2260
2261 (defun feedmail-queue-subject-slug-maker (&optional queue-directory)
2262 "Create a name for storing the message in the queue.
2263 Optional argument QUEUE-DIRECTORY specifies into which directory the
2264 file will be placed. The name is based on the Subject: header (if
2265 there is one). If there is no subject,
2266 `feedmail-queue-default-file-slug' is consulted. Special characters are
2267 mapped to mostly alphanumerics for safety."
2268 (feedmail-say-debug ">in-> feedmail-queue-subject-slug-maker %s" queue-directory)
2269 (let ((eoh-marker) (case-fold-search t) (subject "") (s-point))
2270 (setq eoh-marker (feedmail-find-eoh))
2271 (goto-char (point-min))
2272 ;; get raw subject value (first line, anyhow)
2273 (if (re-search-forward "^Subject:" eoh-marker t)
2274 (progn (setq s-point (point))
2275 (end-of-line)
2276 (setq subject (buffer-substring-no-properties s-point (point)))))
2277 (setq subject (feedmail-tidy-up-slug subject))
2278 (if (zerop (length subject))
2279 (setq subject
2280 (cond
2281 ((stringp feedmail-queue-default-file-slug) feedmail-queue-default-file-slug)
2282 ((fboundp feedmail-queue-default-file-slug)
2283 (save-excursion (funcall feedmail-queue-default-file-slug)))
2284 ((eq feedmail-queue-default-file-slug 'ask)
2285 (file-name-nondirectory
2286 (read-file-name "FQM: Message filename slug? "
2287 (file-name-as-directory queue-directory) subject nil subject)))
2288 (t "no subject"))
2289 ))
2290 ;; one more time, with feeling
2291 (feedmail-tidy-up-slug subject)
2292 ))
2293
2294
2295 (defun feedmail-create-queue-filename (queue-directory)
2296 (feedmail-say-debug ">in-> feedmail-create-queue-filename %s" queue-directory)
2297 (let ((slug "wjc"))
2298 (cond
2299 (feedmail-queue-slug-maker
2300 (save-excursion (setq slug (funcall feedmail-queue-slug-maker queue-directory))))
2301 (feedmail-ask-for-queue-slug
2302 (setq slug (file-name-nondirectory
2303 (read-file-name (concat "FQM: Message filename slug? [" slug "]? ")
2304 (file-name-as-directory queue-directory) slug nil slug))))
2305 )
2306 (setq slug (feedmail-tidy-up-slug slug))
2307 (setq slug (format "%03d-%s" (1+ (nth 2 (feedmail-look-at-queue-directory queue-directory))) slug))
2308 (concat
2309 (expand-file-name slug queue-directory)
2310 feedmail-queue-fqm-suffix)
2311 ))
2312
2313
2314 (defun feedmail-dump-message-to-queue (queue-directory what-event)
2315 (feedmail-say-debug ">in-> feedmail-dump-message-to-queue %s %s" queue-directory what-event)
2316 (or (file-accessible-directory-p queue-directory)
2317 ;; progn to get nil result no matter what
2318 (progn (make-directory queue-directory t) nil)
2319 (file-accessible-directory-p queue-directory)
2320 (error "FQM: Message not queued; trouble with directory %s" queue-directory))
2321 (let ((filename)
2322 (is-fqm)
2323 (is-in-this-dir)
2324 (previous-buffer-file-name buffer-file-name))
2325 (if buffer-file-name
2326 (progn
2327 (setq is-fqm (feedmail-fqm-p buffer-file-name))
2328 (setq is-in-this-dir (string-equal
2329 (directory-file-name
2330 (expand-file-name queue-directory))
2331 (directory-file-name (expand-file-name (file-name-directory buffer-file-name)))))))
2332 ;; if visiting a queued message, just save
2333 (if (and is-fqm is-in-this-dir)
2334 (setq filename buffer-file-name)
2335 (setq filename (feedmail-create-queue-filename queue-directory)))
2336 ;; make binary file on DOS/Windows 95/Windows NT, etc
2337 (let ((coding-system-for-write
2338 (if feedmail-force-binary-write
2339 'no-conversion
2340 coding-system-for-write)))
2341 (write-file filename))
2342 ;; convenient for moving from draft to q, for example
2343 (if (and previous-buffer-file-name (or (not is-fqm) (not is-in-this-dir))
2344 (let (d b s)
2345 (setq b (file-name-nondirectory previous-buffer-file-name))
2346 (setq d (file-name-directory previous-buffer-file-name))
2347 (setq s (substring d (1- (length d))))
2348 (setq d (substring d 0 (1- (length d))))
2349 (setq d (file-name-nondirectory d))
2350 (y-or-n-p (format "FQM: Was previously %s%s%s; delete that? "
2351 d s b))))
2352 (delete-file previous-buffer-file-name))
2353 (if feedmail-nuke-buffer-after-queue
2354 (let ((a-s-file-name buffer-auto-save-file-name))
2355 ;; be aggressive in nuking auto-save files
2356 (and (kill-buffer (current-buffer))
2357 delete-auto-save-files
2358 (file-exists-p a-s-file-name)
2359 (delete-file a-s-file-name))))
2360 (feedmail-say-chatter "Queued in %s" filename)
2361 (if feedmail-queue-chatty
2362 (progn
2363 (feedmail-queue-reminder what-event)
2364 (sit-for feedmail-queue-chatty-sit-for)))))
2365
2366
2367 ;; from a similar function in mail-utils.el
2368 (defun feedmail-rfc822-time-zone (time)
2369 (feedmail-say-debug ">in-> feedmail-rfc822-time-zone %s" time)
2370 (let* ((sec (or (car (current-time-zone time)) 0))
2371 (absmin (/ (abs sec) 60)))
2372 (format "%c%02d%02d" (if (< sec 0) ?- ?+) (/ absmin 60) (% absmin 60))))
2373
2374 (defun feedmail-rfc822-date (arg-time)
2375 (feedmail-say-debug ">in-> feedmail-rfc822-date %s" arg-time)
2376 (let ((time (if arg-time arg-time (current-time)))
2377 (system-time-locale "C"))
2378 (concat
2379 (format-time-string "%a, %e %b %Y %T " time)
2380 (feedmail-rfc822-time-zone time)
2381 )))
2382
2383 (defun feedmail-send-it-immediately-wrapper ()
2384 "Wrapper to catch skip-me-i"
2385 (if (eq 'skip-me-i (catch 'skip-me-i (feedmail-send-it-immediately)))
2386 (error "FQM: Sending...abandoned!")))
2387
2388 (declare-function expand-mail-aliases "mailalias" (beg end &optional exclude))
2389
2390 (defun feedmail-send-it-immediately ()
2391 "Handle immediate sending, including during a queue run."
2392 (feedmail-say-debug ">in-> feedmail-send-it-immediately")
2393 (let ((feedmail-error-buffer
2394 (get-buffer-create " *FQM Outgoing Email Errors*"))
2395 (feedmail-prepped-text-buffer
2396 (get-buffer-create " *FQM Outgoing Email Text*"))
2397 (feedmail-raw-text-buffer (current-buffer))
2398 (feedmail-address-list)
2399 (eoh-marker)
2400 (bcc-holder)
2401 (resent-bcc-holder)
2402 (a-re-rtcb "^Resent-\\(To\\|Cc\\|Bcc\\):")
2403 (a-re-rtc "^Resent-\\(To\\|Cc\\):")
2404 (a-re-rb "^Resent-Bcc:")
2405 (a-re-dtcb "^\\(To\\|Cc\\|Bcc\\):")
2406 (a-re-dtc "^\\(To\\|Cc\\):")
2407 (a-re-db "^Bcc:")
2408 ;; To get a temporary changeable copy.
2409 (mail-header-separator mail-header-separator)
2410 )
2411 (unwind-protect
2412 (save-current-buffer
2413 (set-buffer feedmail-error-buffer) (erase-buffer)
2414 (set-buffer feedmail-prepped-text-buffer) (erase-buffer)
2415
2416 ;; Jam contents of user-supplied mail buffer into our scratch buffer.
2417 (insert-buffer-substring feedmail-raw-text-buffer)
2418
2419 ;; Require one newline at the end.
2420 (goto-char (point-max))
2421 (or (= (preceding-char) ?\n) (insert ?\n))
2422
2423 (let ((case-fold-search nil))
2424 ;; Change header-delimiter to be what mailers expect (empty line).
2425 ;; leaves match data in place or signals error
2426 (feedmail-say-debug "looking for m-h-s \"%s\""
2427 mail-header-separator)
2428 (setq eoh-marker (feedmail-find-eoh))
2429 (feedmail-say-debug "found m-h-s %s" eoh-marker)
2430 (setq mail-header-separator "")
2431 (replace-match ""))
2432 ;; (replace-match "\\1")) ;; might be empty or "\r"
2433
2434 ;; mail-aliases nil = mail-abbrevs.el
2435 (feedmail-say-debug "expanding mail aliases")
2436 (if (or feedmail-force-expand-mail-aliases
2437 (and (fboundp 'expand-mail-aliases) mail-aliases))
2438 (expand-mail-aliases (point-min) eoh-marker))
2439
2440 ;; Make it pretty.
2441 (if feedmail-fill-to-cc (feedmail-fill-to-cc-function eoh-marker))
2442 ;; Ignore any blank lines in the header.
2443 (goto-char (point-min))
2444 (while (and (re-search-forward "\n\n\n*" eoh-marker t)
2445 (< (point) eoh-marker))
2446 (replace-match "\n"))
2447
2448 (let ((case-fold-search t) (addr-regexp))
2449 (goto-char (point-min))
2450 ;; There are some RFC-822 combinations/cases missed here,
2451 ;; but probably good enough and what users expect.
2452 ;;
2453 ;; Use resent-* stuff only if there is at least one non-empty one.
2454 (setq feedmail-is-a-resend
2455 (re-search-forward
2456 ;; Header name, followed by optional whitespace, followed by
2457 ;; non-whitespace, followed by anything, followed by
2458 ;; newline; the idea is empty Resent-* headers are ignored.
2459 "^\\(Resent-To:\\|Resent-Cc:\\|Resent-Bcc:\\)\\s-*\\S-+.*$"
2460 eoh-marker t))
2461 ;; If we say so, gather the Bcc stuff before the main course.
2462 (when (eq feedmail-deduce-bcc-where 'first)
2463 (setq addr-regexp (if feedmail-is-a-resend a-re-rb a-re-db))
2464 (setq feedmail-address-list
2465 (feedmail-deduce-address-list
2466 feedmail-prepped-text-buffer (point-min) eoh-marker
2467 addr-regexp feedmail-address-list)))
2468 ;; The main course.
2469 (setq addr-regexp
2470 (if (memq feedmail-deduce-bcc-where '(first last))
2471 ;; Handled by first or last cases, so don't get
2472 ;; Bcc stuff.
2473 (if feedmail-is-a-resend a-re-rtc a-re-dtc)
2474 ;; Not handled by first or last cases, so also get
2475 ;; Bcc stuff.
2476 (if feedmail-is-a-resend a-re-rtcb a-re-dtcb)))
2477 (setq feedmail-address-list
2478 (feedmail-deduce-address-list
2479 feedmail-prepped-text-buffer (point-min) eoh-marker
2480 addr-regexp feedmail-address-list))
2481 ;; If we say so, gather the Bcc stuff after the main course.
2482 (when (eq feedmail-deduce-bcc-where 'last)
2483 (setq addr-regexp (if feedmail-is-a-resend a-re-rb a-re-db))
2484 (setq feedmail-address-list
2485 (feedmail-deduce-address-list
2486 feedmail-prepped-text-buffer (point-min) eoh-marker
2487 addr-regexp feedmail-address-list)))
2488 (if (not feedmail-address-list)
2489 (error "FQM: Sending...abandoned, no addressees"))
2490 ;; Not needed, but meets user expectations.
2491 (setq feedmail-address-list (nreverse feedmail-address-list))
2492 ;; Find and handle any Bcc fields.
2493 (setq bcc-holder
2494 (feedmail-accume-n-nuke-header eoh-marker "^Bcc:"))
2495 (setq resent-bcc-holder
2496 (feedmail-accume-n-nuke-header eoh-marker "^Resent-Bcc:"))
2497 (when (and bcc-holder (not feedmail-nuke-bcc))
2498 (goto-char (point-min))
2499 (insert bcc-holder))
2500 (when (and resent-bcc-holder (not feedmail-nuke-resent-bcc))
2501 (goto-char (point-min))
2502 (insert resent-bcc-holder))
2503 (goto-char (point-min))
2504
2505 ;; fiddle about, fiddle about, fiddle about....
2506 (feedmail-fiddle-from)
2507 (feedmail-fiddle-sender)
2508 (feedmail-fiddle-x-mailer)
2509 (feedmail-fiddle-message-id
2510 (or feedmail-queue-runner-is-active
2511 (buffer-file-name feedmail-raw-text-buffer)))
2512 (feedmail-fiddle-date
2513 (or feedmail-queue-runner-is-active
2514 (buffer-file-name feedmail-raw-text-buffer)))
2515 (feedmail-fiddle-list-of-fiddle-plexes
2516 feedmail-fiddle-plex-user-list)
2517
2518 ;; don't send out a blank headers of various sorts
2519 ;; (this loses on continued line with a blank first line)
2520 (goto-char (point-min))
2521 (and feedmail-nuke-empty-headers ; hey, who's an empty-header?
2522 (while (re-search-forward "^[A-Za-z0-9-]+:[ \t]*\n"
2523 eoh-marker t)
2524 (replace-match ""))))
2525
2526 (feedmail-say-debug "last chance hook: %s" feedmail-last-chance-hook)
2527 (run-hooks 'feedmail-last-chance-hook)
2528
2529 (save-window-excursion
2530 (let ((fcc (feedmail-accume-n-nuke-header eoh-marker "^Fcc:"))
2531 (also-file)
2532 (confirm (cond
2533 ((eq feedmail-confirm-outgoing 'immediate)
2534 (not feedmail-queue-runner-is-active))
2535 ((eq feedmail-confirm-outgoing 'queued)
2536 feedmail-queue-runner-is-active)
2537 (t feedmail-confirm-outgoing)))
2538 (fullframe (cond
2539 ((eq feedmail-display-full-frame 'immediate)
2540 (not feedmail-queue-runner-is-active))
2541 ((eq feedmail-display-full-frame 'queued)
2542 feedmail-queue-runner-is-active)
2543 (t feedmail-display-full-frame))))
2544 (if fullframe
2545 (progn
2546 (switch-to-buffer feedmail-prepped-text-buffer t)
2547 (delete-other-windows)))
2548 (if (or (not confirm)
2549 (feedmail-one-last-look feedmail-prepped-text-buffer))
2550 (let ((user-mail-address
2551 (feedmail-envelope-deducer eoh-marker)))
2552 (feedmail-say-debug "give it to buffer-eater")
2553 (feedmail-give-it-to-buffer-eater)
2554 (feedmail-say-debug "gave it to buffer-eater")
2555 (if (and (not feedmail-queue-runner-is-active)
2556 (setq also-file
2557 (buffer-file-name feedmail-raw-text-buffer)))
2558 (progn
2559 ;; If a file but not running the queue,
2560 ;; offer to delete it
2561 (setq also-file (expand-file-name also-file))
2562 (when (or feedmail-queue-auto-file-nuke
2563 (y-or-n-p
2564 (format "FQM: Delete message file %s? "
2565 also-file)))
2566 ;; If we delete the affiliated file, get rid
2567 ;; of the file name association and make sure we
2568 ;; don't annoy people with a prompt on exit.
2569 (delete-file also-file)
2570 (with-current-buffer feedmail-raw-text-buffer
2571 (setq buffer-offer-save nil)
2572 (setq buffer-file-name nil)))))
2573 (goto-char (point-min))
2574 ;; Re-insert and handle any Fcc fields (and, optionally,
2575 ;; any Bcc).
2576 (when fcc
2577 (let ((coding-system-for-write
2578 (if (and (memq system-type '(ms-dos windows-nt))
2579 feedmail-force-binary-write)
2580 'no-conversion
2581 coding-system-for-write)))
2582 (unwind-protect
2583 (progn
2584 (insert fcc)
2585 (unless feedmail-nuke-bcc-in-fcc
2586 (if bcc-holder (insert bcc-holder))
2587 (if resent-bcc-holder
2588 (insert resent-bcc-holder)))
2589
2590 (run-hooks 'feedmail-before-fcc-hook)
2591
2592 (when feedmail-nuke-body-in-fcc
2593 (goto-char eoh-marker)
2594 (if (natnump feedmail-nuke-body-in-fcc)
2595 (forward-line feedmail-nuke-body-in-fcc))
2596 (delete-region (point) (point-max)))
2597 (mail-do-fcc eoh-marker))))))
2598 ;; User bailed out of one-last-look.
2599 (if feedmail-queue-runner-is-active
2600 (throw 'skip-me-q 'skip-me-q)
2601 (throw 'skip-me-i 'skip-me-i))
2602 )))) ; unwind-protect body (save-excursion)
2603
2604 ;; unwind-protect cleanup forms.
2605 (kill-buffer feedmail-prepped-text-buffer)
2606 (set-buffer feedmail-error-buffer)
2607 (if (zerop (buffer-size)) (kill-buffer feedmail-error-buffer)
2608 (display-buffer feedmail-error-buffer)
2609 ;; Read fast ... the meter is running.
2610 (if feedmail-queue-runner-is-active
2611 (progn
2612 (ding t)
2613 (feedmail-say-chatter "Sending...failed")))
2614 (error "FQM: Sending...failed"))
2615 (set-buffer feedmail-raw-text-buffer))
2616 ) ; let
2617 (when (and feedmail-queue-chatty (not feedmail-queue-runner-is-active))
2618 (feedmail-queue-reminder 'after-immediate)
2619 (sit-for feedmail-queue-chatty-sit-for)))
2620
2621
2622 (defun feedmail-fiddle-header (name value &optional action folding)
2623 "Internal feedmail function for jamming fields into message header.
2624 NAME, VALUE, ACTION, and FOLDING are the four elements of a
2625 fiddle-plex, as described in the documentation for the variable
2626 `feedmail-fiddle-plex-blurb'."
2627 (feedmail-say-debug ">in-> feedmail-fiddle-header %s %s %s %s"
2628 name value action folding)
2629 (let ((case-fold-search t)
2630 (header-colon (concat (regexp-quote name) ":"))
2631 header-regexp eoh-marker has-like ag-like val-like that-point)
2632 (setq header-regexp (concat "^" header-colon))
2633 (setq eoh-marker (feedmail-find-eoh))
2634 (goto-char (point-min))
2635 (setq has-like (re-search-forward header-regexp eoh-marker t))
2636
2637 (if (not action) (setq action 'supplement))
2638 (cond
2639 ((eq action 'supplement)
2640 ;; trim leading/trailing whitespace
2641 (if (string-match "\\`[ \t\n]+" value)
2642 (setq value (substring value (match-end 0))))
2643 (if (string-match "[ \t\n]+\\'" value)
2644 (setq value (substring value 0 (match-beginning 0))))
2645 (if (> (length value) 0)
2646 (progn
2647 (if feedmail-fiddle-headers-upwardly
2648 (goto-char (point-min))
2649 (goto-char eoh-marker))
2650 (setq that-point (point))
2651 (insert name ": " value "\n")
2652 (if folding (feedmail-fill-this-one that-point (point))))))
2653
2654 ((eq action 'replace)
2655 (if has-like (feedmail-accume-n-nuke-header eoh-marker header-regexp))
2656 (feedmail-fiddle-header name value 'supplement folding))
2657
2658 ((eq action 'create)
2659 (if (not has-like) (feedmail-fiddle-header name value 'supplement folding)))
2660
2661 ((eq action 'combine)
2662 (setq val-like (nth 1 value))
2663 (setq ag-like (or (feedmail-accume-n-nuke-header eoh-marker header-regexp) ""))
2664 ;; get rid of initial header name from first instance (front of string)
2665 (if (string-match (concat header-regexp "[ \t\n]+") ag-like)
2666 (setq ag-like (replace-match "" t t ag-like)))
2667 ;; get rid of embedded header names from subsequent instances
2668 (while (string-match (concat "\n" header-colon "[ \t\n]+") ag-like)
2669 (setq ag-like (replace-match "\n\t" t t ag-like)))
2670 ;; trim leading/trailing whitespace
2671 (if (string-match "\\`[ \t\n]+" ag-like)
2672 (setq ag-like (substring ag-like (match-end 0))))
2673 (if (string-match "[ \t\n]+\\'" ag-like)
2674 (setq ag-like (substring ag-like 0 (match-beginning 0))))
2675 ;; if ag-like is not nil and not an empty string, transform it via a function
2676 ;; call or format operation
2677 (if (> (length ag-like) 0)
2678 (setq ag-like
2679 (cond
2680 ((and (symbolp val-like) (fboundp val-like))
2681 (funcall val-like name ag-like))
2682 ((stringp val-like)
2683 (format val-like ag-like))
2684 (t nil))))
2685 (feedmail-fiddle-header name (concat (nth 0 value) ag-like (nth 2 value)) 'supplement folding)))
2686 ))
2687
2688 (defun feedmail-give-it-to-buffer-eater ()
2689 (feedmail-say-debug ">in-> feedmail-give-it-to-buffer-eater")
2690 (save-excursion
2691 (if feedmail-enable-spray
2692 (mapcar
2693 (lambda (feedmail-spray-this-address)
2694 (let ((spray-buffer (get-buffer-create " *FQM Outgoing Email Spray*")))
2695 (with-current-buffer spray-buffer
2696 (erase-buffer)
2697 ;; not life's most efficient methodology, but spraying isn't
2698 ;; an every-5-minutes event either
2699 (insert-buffer-substring feedmail-prepped-text-buffer)
2700 ;; There's a good case to me made that each separate
2701 ;; transmission of a message in the spray should
2702 ;; have a distinct Message-Id:. There is also a less
2703 ;; compelling argument in the other direction.
2704 ;; I think they technically should have distinct
2705 ;; Message-Id:s, but I doubt that anyone cares,
2706 ;; practically. If someone complains about it, I'll
2707 ;; add it.
2708 (feedmail-fiddle-list-of-spray-fiddle-plexes feedmail-spray-address-fiddle-plex-list)
2709 ;; this (let ) is just in case some buffer eater
2710 ;; is cheating and using the global variable name instead
2711 ;; of its argument to find the buffer
2712 (let ((feedmail-prepped-text-buffer spray-buffer))
2713 (funcall feedmail-buffer-eating-function
2714 feedmail-prepped-text-buffer
2715 feedmail-error-buffer
2716 (list feedmail-spray-this-address))))
2717 (kill-buffer spray-buffer)
2718 ))
2719 feedmail-address-list)
2720 (feedmail-say-debug "calling buffer-eater %s"
2721 feedmail-buffer-eating-function)
2722 (funcall feedmail-buffer-eating-function
2723 feedmail-prepped-text-buffer
2724 feedmail-error-buffer
2725 feedmail-address-list))))
2726
2727
2728 (defun feedmail-envelope-deducer (eoh-marker)
2729 "If `feedmail-deduce-envelope-from' is false, simply return `user-mail-address'.
2730 Else, look for Sender: or From: (or Resent-*) and
2731 return that value."
2732 (feedmail-say-debug ">in-> feedmail-envelope-deducer %s" eoh-marker)
2733 (if (not feedmail-deduce-envelope-from)
2734 user-mail-address
2735 (let ((from-list))
2736 (setq from-list
2737 (feedmail-deduce-address-list
2738 (current-buffer) (point-min) eoh-marker (if feedmail-is-a-resend "^Resent-Sender:" "^Sender:")
2739 from-list))
2740 (if (not from-list)
2741 (setq from-list
2742 (feedmail-deduce-address-list
2743 (current-buffer) (point-min) eoh-marker (if feedmail-is-a-resend "^Resent-From:" "^From:")
2744 from-list)))
2745 (if (and from-list (car from-list)) (car from-list) user-mail-address))))
2746
2747
2748 (defun feedmail-fiddle-from ()
2749 "Fiddle From:."
2750 (feedmail-say-debug ">in-> feedmail-fiddle-from")
2751 ;; default is to fall off the end of the list and do nothing
2752 (cond
2753 ;; nil means do nothing
2754 ((eq nil feedmail-from-line) nil)
2755 ;; t is the same a using the default computation, so compute it and recurse
2756 ;; user-full-name suggested by kpc@ptolemy.arc.nasa.gov (=Kimball Collins)
2757 ;; improvement using user-mail-address suggested by
2758 ;; gray@austin.apc.slb.com (Douglas Gray Stephens)
2759 ;; improvement using mail-host-address suggested by "Jason Eisner" <jason@cs.jhu.edu>
2760 ;; ((this situation really is hopeless, though)
2761 ((eq t feedmail-from-line)
2762 (let ((feedmail-from-line
2763 (let ((at-stuff
2764 (if user-mail-address user-mail-address
2765 (concat (user-login-name) "@"
2766 (or mail-host-address (system-name))))))
2767 (cond
2768 ((eq mail-from-style nil) at-stuff)
2769 ((eq mail-from-style 'parens) (concat at-stuff " (" (user-full-name) ")"))
2770 ((eq mail-from-style 'angles) (concat "\"" (user-full-name) "\" <" at-stuff ">"))
2771 ))))
2772 (feedmail-fiddle-from)))
2773
2774 ;; if it's a string, simply make a fiddle-plex out of it and recurse
2775 ((stringp feedmail-from-line)
2776 (let ((feedmail-from-line (list "ignored" feedmail-from-line 'create)))
2777 (feedmail-fiddle-from)))
2778
2779 ;; if it's a function, call it and recurse with the resulting value
2780 ((and (symbolp feedmail-from-line) (fboundp feedmail-from-line))
2781 (let ((feedmail-from-line (funcall feedmail-from-line)))
2782 (feedmail-fiddle-from)))
2783
2784 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2785 ((listp feedmail-from-line)
2786 (feedmail-fiddle-header
2787 (if feedmail-is-a-resend "Resent-From" "From")
2788 (nth 1 feedmail-from-line) ; value
2789 (nth 2 feedmail-from-line) ; action
2790 (nth 3 feedmail-from-line))))) ; folding
2791
2792
2793 (defun feedmail-fiddle-sender ()
2794 "Fiddle Sender:."
2795 (feedmail-say-debug ">in-> feedmail-fiddle-sender")
2796 ;; default is to fall off the end of the list and do nothing
2797 (cond
2798 ;; nil means do nothing
2799 ((eq nil feedmail-sender-line) nil)
2800 ;; t is not allowed, but handled it just to avoid bugs later
2801 ((eq t feedmail-sender-line) nil)
2802
2803 ;; if it's a string, simply make a fiddle-plex out of it and recurse
2804 ((stringp feedmail-sender-line)
2805 (let ((feedmail-sender-line (list "ignored" feedmail-sender-line 'create)))
2806 (feedmail-fiddle-sender)))
2807
2808 ;; if it's a function, call it and recurse with the resulting value
2809 ((and (symbolp feedmail-sender-line) (fboundp feedmail-sender-line))
2810 (let ((feedmail-sender-line (funcall feedmail-sender-line)))
2811 (feedmail-fiddle-sender)))
2812
2813 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2814 ((listp feedmail-sender-line)
2815 (feedmail-fiddle-header
2816 (if feedmail-is-a-resend "Resent-Sender" "Sender")
2817 (nth 1 feedmail-sender-line) ; value
2818 (nth 2 feedmail-sender-line) ; action
2819 (nth 3 feedmail-sender-line))))) ; folding
2820
2821
2822 (defun feedmail-default-date-generator (maybe-file)
2823 "Default function for generating Date: header contents."
2824 (feedmail-say-debug ">in-> feedmail-default-date-generator")
2825 (when maybe-file
2826 (feedmail-say-debug (concat "4 cre " (feedmail-rfc822-date (nth 4 (file-attributes maybe-file)))))
2827 (feedmail-say-debug (concat "5 mod " (feedmail-rfc822-date (nth 5 (file-attributes maybe-file)))))
2828 (feedmail-say-debug (concat "6 sta " (feedmail-rfc822-date (nth 6 (file-attributes maybe-file))))))
2829 (let ((date-time))
2830 (if (and (not feedmail-queue-use-send-time-for-date) maybe-file)
2831 (setq date-time (nth 5 (file-attributes maybe-file))))
2832 (feedmail-rfc822-date date-time))
2833 )
2834
2835
2836 (defun feedmail-fiddle-date (maybe-file)
2837 "Fiddle Date:. See documentation of `feedmail-date-generator'."
2838 (feedmail-say-debug ">in-> feedmail-fiddle-date")
2839 ;; default is to fall off the end of the list and do nothing
2840 (cond
2841 ;; nil means do nothing
2842 ((eq nil feedmail-date-generator) nil)
2843 ;; t is the same a using the function feedmail-default-date-generator, so let it and recurse
2844 ((eq t feedmail-date-generator)
2845 (let ((feedmail-date-generator (feedmail-default-date-generator maybe-file)))
2846 (feedmail-fiddle-date maybe-file)))
2847
2848 ;; if it's a string, simply make a fiddle-plex out of it and recurse
2849 ((stringp feedmail-date-generator)
2850 (let ((feedmail-date-generator (list "ignored" feedmail-date-generator 'create)))
2851 (feedmail-fiddle-date maybe-file)))
2852
2853 ;; if it's a function, call it and recurse with the resulting value
2854 ((and (symbolp feedmail-date-generator) (fboundp feedmail-date-generator))
2855 (let ((feedmail-date-generator (funcall feedmail-date-generator maybe-file)))
2856 (feedmail-fiddle-date maybe-file)))
2857
2858 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2859 ((listp feedmail-date-generator)
2860 (feedmail-fiddle-header
2861 (if feedmail-is-a-resend "Resent-Date" "Date")
2862 (nth 1 feedmail-date-generator) ; value
2863 (nth 2 feedmail-date-generator) ; action
2864 (nth 3 feedmail-date-generator))))) ; folding
2865
2866
2867 (defun feedmail-default-message-id-generator (maybe-file)
2868 "Default function for generating Message-Id: header contents.
2869 Based on a date and a sort of random number for tie breaking. Unless
2870 `feedmail-message-id-suffix' is defined, uses `user-mail-address', so be
2871 sure it's set. If both are nil, creates a quasi-random suffix that is
2872 probably not appropriate for you."
2873 (feedmail-say-debug ">in-> feedmail-default-message-id-generator %s"
2874 maybe-file)
2875 (let ((date-time)
2876 (system-time-locale "C")
2877 (end-stuff (if feedmail-message-id-suffix feedmail-message-id-suffix user-mail-address)))
2878 (if (not end-stuff) (setq end-stuff (format "%d.example.com" (random))))
2879 (if (string-match "^\\(.*\\)@" end-stuff)
2880 (setq end-stuff
2881 (concat (if (equal (match-beginning 1) (match-end 1)) "" "-") end-stuff))
2882 (setq end-stuff (concat "@" end-stuff)))
2883 (if (and (not feedmail-queue-use-send-time-for-message-id) maybe-file)
2884 (setq date-time (nth 5 (file-attributes maybe-file))))
2885 (format "<%d-%s%s%s>"
2886 (mod (random) 10000)
2887 (format-time-string "%a%d%b%Y%H%M%S" date-time)
2888 (feedmail-rfc822-time-zone date-time)
2889 end-stuff))
2890 )
2891
2892 (defun feedmail-fiddle-message-id (maybe-file)
2893 "Fiddle Message-Id:. See documentation of `feedmail-message-id-generator'."
2894 (feedmail-say-debug ">in-> feedmail-fiddle-message-id %s" maybe-file)
2895 ;; default is to fall off the end of the list and do nothing
2896 (cond
2897 ;; nil means do nothing
2898 ((eq nil feedmail-message-id-generator) nil)
2899 ;; t is the same a using the function feedmail-default-message-id-generator, so let it and recurse
2900 ((eq t feedmail-message-id-generator)
2901 (let ((feedmail-message-id-generator (feedmail-default-message-id-generator maybe-file)))
2902 (feedmail-fiddle-message-id maybe-file)))
2903
2904 ;; if it's a string, simply make a fiddle-plex out of it and recurse
2905 ((stringp feedmail-message-id-generator)
2906 (let ((feedmail-message-id-generator (list "ignored" feedmail-message-id-generator 'create)))
2907 (feedmail-fiddle-message-id maybe-file)))
2908
2909 ;; if it's a function, call it and recurse with the resulting value
2910 ((and (symbolp feedmail-message-id-generator) (fboundp feedmail-message-id-generator))
2911 (let ((feedmail-message-id-generator (funcall feedmail-message-id-generator maybe-file)))
2912 (feedmail-fiddle-message-id maybe-file)))
2913
2914 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2915 ((listp feedmail-message-id-generator)
2916 (feedmail-fiddle-header
2917 (if feedmail-is-a-resend "Resent-Message-Id" "Message-Id")
2918 (nth 1 feedmail-message-id-generator) ; value
2919 (nth 2 feedmail-message-id-generator) ; action
2920 (nth 3 feedmail-message-id-generator))))) ; folding
2921
2922
2923 (defun feedmail-default-x-mailer-generator ()
2924 "Default function for generating X-Mailer: header contents."
2925 (concat
2926 (let ((case-fold-search t)) (if (string-match "emacs" emacs-version) "" "emacs "))
2927 emacs-version " (via feedmail " feedmail-patch-level
2928 (if feedmail-queue-runner-is-active " Q" " I")
2929 (if feedmail-enable-spray "S" "")
2930 (if feedmail-x-mailer-line-user-appendage ") " ")")
2931 feedmail-x-mailer-line-user-appendage))
2932
2933
2934 (defun feedmail-fiddle-x-mailer ()
2935 "Fiddle X-Mailer:. See documentation of `feedmail-x-mailer-line'."
2936 (feedmail-say-debug ">in-> feedmail-fiddle-x-mailer")
2937 ;; default is to fall off the end of the list and do nothing
2938 (cond
2939 ;; nil means do nothing
2940 ((eq nil feedmail-x-mailer-line) nil)
2941 ;; t is the same a using the function feedmail-default-x-mailer-generator, so let it and recurse
2942 ((eq t feedmail-x-mailer-line)
2943 (let ((feedmail-x-mailer-line (feedmail-default-x-mailer-generator)))
2944 (feedmail-fiddle-x-mailer)))
2945
2946 ;; if it's a string, simply make a fiddle-plex out of it and recurse
2947 ((stringp feedmail-x-mailer-line)
2948 (let ((feedmail-x-mailer-line (list "ignored" (list feedmail-x-mailer-line ";\n\t%s") 'combine)))
2949 (feedmail-fiddle-x-mailer)))
2950
2951 ;; if it's a function, call it and recurse with the resulting value
2952 ((and (symbolp feedmail-x-mailer-line) (fboundp feedmail-x-mailer-line))
2953 (let ((feedmail-x-mailer-line (funcall feedmail-x-mailer-line)))
2954 (feedmail-fiddle-x-mailer)))
2955
2956 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2957 ((listp feedmail-x-mailer-line)
2958 (feedmail-fiddle-header
2959 (if feedmail-is-a-resend "X-Resent-Mailer" "X-Mailer")
2960 (nth 1 feedmail-x-mailer-line) ; value
2961 (nth 2 feedmail-x-mailer-line) ; action
2962 (nth 3 feedmail-x-mailer-line))))) ; folding
2963
2964
2965 (defun feedmail-fiddle-spray-address (addy-plex)
2966 "Fiddle header for single spray address. Uses `feedmail-spray-this-address'."
2967 (feedmail-say-debug ">in-> feedmail-fiddle-spray-address %s" addy-plex)
2968 ;; default is to fall off the end of the list and do nothing
2969 (cond
2970 ;; nil means do nothing
2971 ((eq nil addy-plex) nil)
2972 ;; t means the same as using "To:" and unembellished addy
2973 ((eq t addy-plex)
2974 (let ((addy-plex (list "To" feedmail-spray-this-address)))
2975 (feedmail-fiddle-spray-address addy-plex)))
2976
2977 ;; if it's a string, simply make a fiddle-plex out of it and recurse, assuming
2978 ;; the string names a header field (e.g., "To")
2979 ((stringp addy-plex)
2980 (let ((addy-plex (list addy-plex feedmail-spray-this-address)))
2981 (feedmail-fiddle-spray-address addy-plex)))
2982
2983 ;; if it's a function, call it and recurse with the resulting value
2984 ((and (symbolp addy-plex) (fboundp addy-plex))
2985 (let ((addy-plex (funcall addy-plex)))
2986 (feedmail-fiddle-spray-address addy-plex)))
2987
2988 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
2989 ((listp addy-plex)
2990 (feedmail-fiddle-header
2991 (nth 0 addy-plex) ; name
2992 (nth 1 addy-plex) ; value
2993 (nth 2 addy-plex) ; action
2994 (nth 3 addy-plex))))) ; folding
2995
2996
2997 (defun feedmail-fiddle-list-of-spray-fiddle-plexes (list-of-fiddle-plexes)
2998 "Fiddling based on a list of fiddle-plexes for spraying."
2999 (feedmail-say-debug ">in-> feedmail-fiddle-list-of-spray-fiddle-plexes")
3000 ;; default is to fall off the end of the list and do nothing
3001 (let ((lofp list-of-fiddle-plexes) fp)
3002 (if (listp lofp)
3003 (while lofp
3004 (setq fp (car lofp))
3005 (setq lofp (cdr lofp))
3006 (feedmail-fiddle-spray-address fp))
3007 (feedmail-fiddle-spray-address lofp))))
3008
3009
3010 (defun feedmail-fiddle-list-of-fiddle-plexes (list-of-fiddle-plexes)
3011 "Fiddling based on a list of fiddle-plexes. Values t, nil, and string are pointless."
3012 (feedmail-say-debug ">in-> feedmail-fiddle-list-of-fiddle-plexes")
3013 ;; default is to fall off the end of the list and do nothing
3014 (let ((lofp list-of-fiddle-plexes) fp)
3015 (while lofp
3016 (setq fp (car lofp))
3017 (setq lofp (cdr lofp))
3018 (cond
3019
3020 ;; if it's a function, call it and recurse with the resulting value
3021 ((and (symbolp fp) (fboundp fp))
3022 (let ((lofp (list (funcall fp)))) (feedmail-fiddle-list-of-fiddle-plexes lofp)))
3023
3024 ;; if it's a list, it must be a fiddle-plex -- so fiddle, man, fiddle
3025 ((listp fp)
3026 (feedmail-fiddle-header
3027 (nth 0 fp)
3028 (nth 1 fp) ; value
3029 (nth 2 fp) ; action
3030 (nth 3 fp))))))) ; folding
3031
3032
3033 (defun feedmail-accume-n-nuke-header (header-end header-regexp)
3034 "Delete headers matching a regexp and their continuation lines.
3035 There may be multiple such lines, and each may have arbitrarily
3036 many continuation lines. Return an accumulation of the deleted
3037 headers, including the intervening newlines."
3038 (feedmail-say-debug ">in-> feedmail-accume-n-nuke-header %s %s"
3039 header-end header-regexp)
3040 (let ((case-fold-search t) (dropout))
3041 (save-excursion
3042 (goto-char (point-min))
3043 ;; iterate over all matching lines
3044 (while (re-search-forward header-regexp header-end t)
3045 (forward-line 1)
3046 (setq dropout (concat dropout (buffer-substring-no-properties (match-beginning 0) (point))))
3047 (delete-region (match-beginning 0) (point))
3048 ;; get rid of any continuation lines
3049 (while (and (looking-at "^[ \t].*\n") (< (point) header-end))
3050 (forward-line 1)
3051 (setq dropout (concat dropout (buffer-substring-no-properties (match-beginning 0) (point))))
3052 (replace-match ""))))
3053 (identity dropout)))
3054
3055 (defun feedmail-fill-to-cc-function (header-end)
3056 "Smart filling of address headers (don't be fooled by the name).
3057 The filling tries to avoid splitting lines except at commas. This
3058 avoids, in particular, splitting within parenthesized comments in
3059 addresses. Headers filled include From:, Reply-To:, To:, Cc:, Bcc:,
3060 Resent-To:, Resent-Cc:, and Resent-Bcc:."
3061 (feedmail-say-debug ">in-> feedmail-fill-to-cc-function")
3062 (let ((case-fold-search t)
3063 this-line
3064 this-line-end)
3065 (save-excursion
3066 (goto-char (point-min))
3067 ;; iterate over all To:/Cc:, etc, lines
3068 (while
3069 (re-search-forward
3070 "^\\(From:\\|Reply-To:\\|To:\\|Cc:\\|Bcc:\\|Resent-To:\\|Resent-Cc:\\|Resent-Bcc:\\)"
3071 header-end t)
3072 (setq this-line (match-beginning 0))
3073 ;; replace 0 or more leading spaces with a single space
3074 (and (looking-at "[ \t]*") (replace-match " "))
3075 (forward-line 1)
3076 ;; get any continuation lines
3077 (while (and (looking-at "[ \t]+") (< (point) header-end))
3078 (forward-line 1))
3079 (setq this-line-end (point-marker))
3080 (save-excursion (feedmail-fill-this-one this-line this-line-end))
3081 ))))
3082
3083
3084 (defun feedmail-fill-this-one (this-line this-line-end)
3085 "In-place smart filling of the region bounded by the two arguments."
3086 (feedmail-say-debug ">in-> feedmail-fill-this-one")
3087 (let ((fill-prefix "\t")
3088 (fill-column feedmail-fill-to-cc-fill-column))
3089 ;; The general idea is to break only on commas. Collapse
3090 ;; multiple whitespace to a single blank; change
3091 ;; all the blanks to something unprintable; change the
3092 ;; commas to blanks; fill the region; change it back.
3093 (goto-char this-line)
3094 (while (re-search-forward "\\s-+" (1- this-line-end) t)
3095 (replace-match " "))
3096
3097 (subst-char-in-region this-line this-line-end ? 2 t) ; blank->C-b
3098 (subst-char-in-region this-line this-line-end ?, ? t) ; comma->blank
3099
3100 (fill-region-as-paragraph this-line this-line-end)
3101
3102 (subst-char-in-region this-line this-line-end ? ?, t) ; comma<-blank
3103 (subst-char-in-region this-line this-line-end 2 ? t) ; blank<-C-b
3104
3105 ;; look out for missing commas before continuation lines
3106 (goto-char this-line)
3107 (while (re-search-forward "\\([^,]\\)\n\t[ ]*" this-line-end t)
3108 (replace-match "\\1,\n\t"))
3109 ))
3110
3111
3112 (defun feedmail-deduce-address-list (message-buffer header-start header-end addr-regexp address-list)
3113 "Get address list with all comments and other excitement trimmed.
3114 Addresses are collected only from headers whose names match the fourth
3115 argument. Returns a list of strings. Duplicate addresses will have
3116 been weeded out."
3117 (feedmail-say-debug ">in-> feedmail-deduce-address-list %s %s" addr-regexp address-list)
3118 (let ((simple-address)
3119 (address-blob)
3120 (this-line)
3121 (this-line-end))
3122 (unwind-protect
3123 (with-current-buffer (get-buffer-create " *FQM scratch*")
3124 (erase-buffer)
3125 (insert-buffer-substring message-buffer header-start header-end)
3126 (goto-char (point-min))
3127 (let ((case-fold-search t))
3128 (while (re-search-forward addr-regexp (point-max) t)
3129 (replace-match "")
3130 (setq this-line (match-beginning 0))
3131 (forward-line 1)
3132 ;; get any continuation lines
3133 (while (and (looking-at "^[ \t]+") (< (point) (point-max)))
3134 (forward-line 1))
3135 (setq this-line-end (point-marker))
3136 ;; only keep if we don't have it already
3137 (setq address-blob
3138 (mail-strip-quoted-names (buffer-substring-no-properties this-line this-line-end)))
3139 (while (string-match "\\([, \t\n\r]*\\)\\([^, \t\n\r]+\\)" address-blob)
3140 (setq simple-address (substring address-blob (match-beginning 2) (match-end 2)))
3141 (setq address-blob (replace-match "" t t address-blob))
3142 (if (not (member simple-address address-list))
3143 (add-to-list 'address-list simple-address)))
3144 ))
3145 (kill-buffer nil)))
3146 (identity address-list)))
3147
3148
3149 (defun feedmail-one-last-look (feedmail-prepped-text-buffer)
3150 "Offer the user one last chance to give it up."
3151 (feedmail-say-debug ">in-> feedmail-one-last-look")
3152 (save-excursion
3153 (save-window-excursion
3154 (switch-to-buffer feedmail-prepped-text-buffer)
3155 (if (and (fboundp 'y-or-n-p-with-timeout) (numberp feedmail-confirm-outgoing-timeout))
3156 (y-or-n-p-with-timeout
3157 "FQM: Send this email? "
3158 (abs feedmail-confirm-outgoing-timeout)
3159 (> feedmail-confirm-outgoing-timeout 0))
3160 (y-or-n-p "FQM: Send this email? "))
3161 )))
3162
3163 (defun feedmail-fqm-p (might-be)
3164 "Internal; does filename end with FQM suffix?"
3165 (feedmail-say-debug ">in-> feedmail-fqm-p %s" might-be)
3166 (string-match (concat (regexp-quote feedmail-queue-fqm-suffix) "$") might-be))
3167
3168 (defun feedmail-say-debug (format &optional a1 a2 a3 a4 a5 a6 a7 a8 a9)
3169 "Internal; emits debug messages in standard format."
3170 (when feedmail-debug
3171 (funcall 'message (concat "FQM DB: " format) a1 a2 a3 a4 a5 a6 a7 a8 a9)
3172 (and feedmail-debug-sit-for (not (= 0 feedmail-debug-sit-for))
3173 (sit-for feedmail-debug-sit-for))))
3174
3175 (defun feedmail-say-chatter (format &optional a1 a2 a3 a4 a5 a6 a7 a8 a9)
3176 "Internal; emits queue chatter messages in standard format."
3177 (when feedmail-queue-chatty
3178 (funcall 'message (concat "FQM: " format) a1 a2 a3 a4 a5 a6 a7 a8 a9)
3179 (and feedmail-queue-chatty-sit-for (not (= 0 feedmail-queue-chatty-sit-for))
3180 (sit-for feedmail-queue-chatty-sit-for))))
3181
3182 (defun feedmail-find-eoh (&optional noerror)
3183 "Internal; finds the end of message header fields, returns mark just before it"
3184 ;; all this funny business with line endings is to account for CRLF
3185 ;; weirdness that I don't think I'll ever figure out
3186 (feedmail-say-debug ">in-> feedmail-find-eoh %s" noerror)
3187 (let ((mhs mail-header-separator)
3188 (alt-mhs feedmail-queue-alternative-mail-header-separator)
3189 r-mhs r-alt-mhs)
3190 (setq r-mhs (concat "^" (regexp-quote mhs) "$"))
3191 (setq r-alt-mhs (concat "^" (regexp-quote (or alt-mhs "")) "$"))
3192 (save-excursion
3193 (goto-char (point-min))
3194 (if (or (re-search-forward r-mhs nil t)
3195 (and alt-mhs (re-search-forward r-alt-mhs nil t)))
3196 (progn
3197 (beginning-of-line)
3198 (point-marker))
3199 (if noerror
3200 nil
3201 (error "FQM: Can't find message-header-separator or alternate"))))))
3202
3203 (provide 'feedmail)
3204
3205 ;;; feedmail.el ends here