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