1
;;; vm-pine.el --- draft handling and other neat functions for VM
3
;; Copyright (C) 1998-2002 Robert Fenk
6
;; Status: Tested with XEmacs 21.1.10 & GNU Emacs 20.7 & VM 6.95
7
;; Keywords: vm draft handling
8
;; X-URL: http://www.robf.de/Hacking/elisp
9
;; X-RCS: $Id: vm-pine.el,v 1.50 2004/04/29 21:12:38 fenk Exp $
12
;; This code is free software; you can redistribute it and/or modify
13
;; it under the terms of the GNU General Public License as published by
14
;; the Free Software Foundation; either version 1, or (at your option)
17
;; This program is distributed in the hope that it will be useful,
18
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
;; GNU General Public License for more details.
22
;; You should have received a copy of the GNU General Public License
23
;; along with this program; if not, write to the Free Software
24
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
;; This package provides the following new features for VM:
30
;; A Pine-like postpone message function and folder. There are two new
31
;; functions. `vm-postpone-message' bound to [C-c C-p] in
32
;; the `vm-mail-mode' and the function `vm-continue-postponed-message'
33
;; is bound to [C] in a folder buffer.
34
;; The `vm-continue-what-message' imitates Pines message composing.
35
;; You can set `vm-mode-map' in the following way to get Pine-like.
37
;; (define-key vm-mode-map "m" 'vm-continue-what-message)
39
;; If you have postponed messages you will be asked if you want to continue
40
;; their composing, if you say "yes" you will visit the `vm-postponed-folder'
41
;; and you can select the message you would like to continue and press "m"
42
;; again! However be aware this works currently only if you expunge all
43
;; messages marked for deletion and save the postponed folder.
45
;; You can also bind it to "C-x m" in order to check for postponed messages
46
;; when composing a message without starting VM.
48
;; (autoload 'vm-continue-what-message-other-window "vm-pine" "" t)
49
;; (global-set-key "\C-xm" 'vm-continue-what-message-other-window)
52
;; Three new mail header insertion functions make life easier. The
53
;; bindings and names are:
54
;; "\C-c\C-f\C-a" vm-mail-return-receipt-to
55
;; "\C-c\C-f\C-p" vm-mail-priority
56
;; "\C-c\C-f\C-f" vm-mail-fcc
57
;; The variables `vm-mail-return-receipt-to' and `vm-mail-priority'
58
;; can be used to configure the inserted headers.
59
;; `vm-mail-fcc' can be configured by setting the variable
60
;; `vm-mail-folder-alist' which has the same syntax and default
61
;; value as `vm-auto-folder-alist'.
62
;; You may also add `vm-mail-auto-fcc' to `vm-reply-hook' in order to
63
;; automatically setup the FCC header according to the variable
64
;; `vm-mail-folder-alist'.
65
;; An there's another fcc-function `vm-mail-to-fcc' which set the FCC
66
;; according to the recipients email-address.
68
;;; Bug reports and feature requests:
69
;; Please send a backtrace and the version number of vm-pine.el!
70
;; Feature requests are welcome!
74
;; Attempt to handle older/other emacs.
81
(if (not (boundp 'user-mail-address))
82
(if (functionp 'user-mail-address)
83
(setq user-mail-address (user-mail-address))
84
(setq user-mail-address "unknown")
85
(message "Please set the variable `user-mail-address'!!!")
93
"Pine inspired extensions to VM."
96
;;-----------------------------------------------------------------------------
98
(defun vm-summary-function-f (m)
99
"Return the recipient or newsgroup for uninteresting senders.
100
If the \"From:\" header contains the user login or full name then
101
this function returns the \"To:\" or \"Newsgroups:\" header field with a
104
For example the outgoing message box will now list to whom you sent the
105
messages. Use `vm-fix-summary!!!' to update the summary of a folder! With
106
loaded BBDB it uses `vm-summary-function-B' to obtain the full name of the
107
sender. The only difference to VMs default behavior is the honoring of
108
messages sent to news groups. ;c)
110
See also: `vm-summary-uninteresting-senders'"
112
(let ((case-fold-search t)
113
(headers '(("From:" "")
114
("Newsgroups:" "News:")
116
"Resent-To:" "Resent-CC:" "Resent-BCC:"
117
("Sender:" "") ("Resent-From:" "Resent:")))
123
(while (and (not address) headers)
124
(if (listp (car headers))
125
(setq header-name (caar headers) arrow (cadar headers))
126
(setq header-name (car headers) arrow (concat header-name " ")))
127
(setq addresses (vm-get-header-contents m header-name))
129
(setq addresses (vm-decode-mime-encoded-words-in-string addresses)
131
(or (if (functionp 'bbdb-extract-address-components)
132
(bbdb-extract-address-components addresses t))
133
(list (mail-extract-address-components addresses))
135
(if (not first) (setq first (car addresses)))
137
(if (or (not vm-summary-uninteresting-senders)
138
(and vm-summary-uninteresting-senders
139
(not (string-match vm-summary-uninteresting-senders
140
(format "%s" (car addresses))))))
141
(setq address (car addresses) addresses nil))
142
(setq addresses (cdr addresses)))
143
(setq headers (cdr headers)))
145
(if (and (null address) (null first))
147
(if (and (null address) first)
148
(setq address first))
150
(cond ((functionp 'bbdb/vm-alternate-full-name)
151
(or (bbdb/vm-alternate-full-name (cadr address))
154
(t (or (car address) (cadr address))))))))
156
;;-----------------------------------------------------------------------------
158
(defcustom vm-postponed-header "X-VM-postponed-data: "
159
"Additional header which is inserted to postponed messages.
160
It is used for internal things and should not be modified.
161
It is a lisp list which currently contains the following items:
162
<date of the postponing>
163
<reply references list>
164
<forward references list>
165
<redistribute references list>
166
while the last three are set by `vm-get-persistent-message-ids-for'."
171
(defcustom vm-postponed-attribute "P"
172
"Summary string that will be inserted by `vm-summary-function-p' for
178
(defun vm-summary-function-p (m)
179
"Return 'P' for postponed messages."
181
(if (vm-get-header-contents m vm-postponed-header)
185
;;-----------------------------------------------------------------------------
186
;; A Pine-like postponed folder handling
188
(defcustom vm-postponed-folder "postponed"
189
"The name of the folder where postponed messages are saved."
194
(defcustom vm-postponed-message-headers '("From:" "Organization:"
201
"X-Priority:" "Priority:")
202
"Similar to `vm-forwarded-headers'.
203
A list of headers that should be kept, when continuing a postponed message.
205
The following mime headers should not be kept, since this breaks things:
206
Mime-Version, Content-Type, Content-Transfer-Encoding."
207
:type '(repeat (string))
211
(defcustom vm-postponed-message-discard-header-regexp nil
212
"Similar to `vm-unforwarded-header-regexp'.
213
A regular expression matching all headers that should be discard when
214
when continuing a postponed message."
219
(defcustom vm-continue-postponed-message-hook nil
220
"List of hook functions to be run after continuing a postponed message."
225
(defcustom vm-postpone-message-hook nil
226
"List of hook functions to be run before postponing a message."
230
(defvar vm-postponed-message-folder-buffer nil
231
"Buffer of source folder.
232
This is only for internal use of vm-pine.el!!!")
234
;;-----------------------------------------------------------------------------
235
(define-key vm-mode-map [C] 'vm-continue-postponed-message)
237
;;-----------------------------------------------------------------------------
238
(defun vm-get-persistent-message-ids-for (mlist)
239
"Return a list of message id and folder name of all messages in MLIST."
240
(let (mp midlist folder mid f)
243
folder (buffer-name (vm-buffer-of mp))
244
mid (vm-message-id-of mp)
245
f (assoc folder midlist))
248
(setcdr f (cons mid (cdr f)))
249
(add-to-list 'midlist (list folder mid))))
250
(setq mlist (cdr mlist)))
253
(defun vm-get-message-pointers-for (msgidlist)
254
"Return the message pointers belonging to the messages listed in MSGIDLIST.
255
MSGIDLIST is a list as returned by `vm-get-persistent-message-ids-for'."
256
(let (folder vm-message-pointers)
259
(setq folder (caar msgidlist))
260
(if (file-exists-p (expand-file-name folder
261
(or vm-folder-directory "~/Mail")))
264
(cond ((bufferp folder)
267
(if (get-buffer folder)
268
(set-buffer (get-buffer folder))
269
(vm-visit-folder folder)))))
270
(vm-select-folder-buffer)
273
(goto-char (point-min))
274
(let ((msgid-regexp (concat "^Message-Id:\\s-*"
275
(regexp-opt (cdar msgidlist))))
276
(point-max (point-max))
277
(case-fold-search t))
279
(while (re-search-forward msgid-regexp point-max t)
280
(let ((point (point))
281
(mp vm-message-list))
283
(if (and (>= point (vm-start-of (car mp)))
284
(<= point (vm-end-of (car mp))))
285
(setq vm-message-pointers (cons (car mp)
288
(setq mp (cdr mp)))))))))
289
(message "The folder %s does not exist. Maybe it was virtual." folder))
290
(setq msgidlist (cdr msgidlist)))
291
vm-message-pointers))
293
;;-----------------------------------------------------------------------------
295
(defun vm-continue-postponed-message (&optional silent)
296
"Continue composing of the currently selected message.
297
Before continuing the composition you may decode the presentation as
298
you like, by pressing [D] and viewing part of the message!
299
Then current message is copied to a new buffer and the vm-mail-mode is
300
entered. When every thing is finished the hook functions in
301
`vm-mail-mode-hook' and `vm-continue-postponed-message-hook' are
302
executed. When called with a prefix argument it will not switch to
303
the composition buffer, this may be used for automatic editing of
306
The variables `vm-postponed-message-headers' and
307
`vm-postponed-message-discard-header-regexp' control which
308
headers are copied to the composition buffer.
310
In `vm-mail-mode' this is bound to [C].
311
Optional argument SILENT is positiv then act in background (no frame
315
(vm-session-initialization)
316
(vm-follow-summary-cursor)
317
(vm-select-folder-buffer)
318
(vm-check-for-killed-summary)
319
(vm-check-for-killed-presentation)
320
(vm-error-if-folder-empty)
322
(if (eq vm-system-state 'previewing)
323
(vm-show-current-message))
327
(let* ((folder-buffer (current-buffer))
328
(presentation-buffer vm-presentation-buffer)
329
(vmp vm-message-pointer)
330
(is-decoded vm-mime-decoded)
331
(hstart (vm-headers-of (car vmp)))
332
(tstart (vm-text-of (car vmp)))
333
(tend (- (vm-end-of (car vmp)) 1))
334
(to (format "mail to %s" (vm-get-header-contents (car vmp)
336
(vm-pp-data (vm-get-header-contents (car vmp)
337
vm-postponed-header)))
339
;; Prepare the composition buffer
340
(if (and to (string-match "[^,\n<(]+" to))
341
(setq to (match-string 0 to)))
344
(let ((vm-mail-hook nil)
345
(vm-mail-mode-hook nil)
346
(this-command 'vm-mail))
347
(vm-mail-internal to))
348
(set-buffer (generate-new-buffer to))
349
(setq default-directory (expand-file-name
350
(or vm-folder-directory "~/")))
351
(auto-save-mode (if auto-save-default 1 -1))
352
(let ((mail-mode-hook nil)
353
(mail-setup-hook nil))
355
(setq vm-mail-buffer folder-buffer))
357
(make-local-variable 'vm-postponed-message-folder-buffer)
358
(setq vm-postponed-message-folder-buffer
359
(vm-buffer-of (vm-real-message-of (car vmp))))
360
(make-local-variable 'vm-message-pointer)
361
(setq vm-message-pointer vmp)
362
(make-local-hook 'mail-send-hook)
363
(add-hook 'mail-send-hook 'vm-delete-postponed-message t t)
366
;; set the VM variables for setting source message attributes
368
(make-local-variable 'vm-reply-list)
369
(make-local-variable 'vm-forward-list)
370
(make-local-variable 'vm-redistribute-list)
371
(setq vm-pp-data (read vm-pp-data)
373
(vm-get-message-pointers-for (nth 1 vm-pp-data))
375
(vm-get-message-pointers-for (nth 2 vm-pp-data))
377
(vm-get-message-pointers-for (nth 3 vm-pp-data)))
378
(if vm-reply-list (setq vm-system-state 'replying))
379
(if vm-forward-list (setq vm-system-state 'forwarding))
380
(if vm-redistribute-list (setq vm-system-state 'redistributing)))
383
(insert-buffer-substring folder-buffer hstart tstart)
384
(beginning-of-buffer)
385
(cond ((or (vm-mime-plain-message-p (car vmp)) is-decoded)
386
(vm-reorder-message-headers nil
387
vm-postponed-message-headers
388
vm-postponed-message-discard-header-regexp))
389
(t ; copy undecoded messages with mime headers
390
(vm-reorder-message-headers nil
391
(append '("MIME-Version:" "Content-type:")
392
vm-postponed-message-headers)
393
vm-postponed-message-discard-header-regexp)))
394
(vm-decode-mime-encoded-words)
395
(search-forward-regexp "\n\n")
396
(replace-match (concat "\n" mail-header-separator "\n") t t)
398
;; Add message body as previewed
399
(goto-char (point-max))
400
(if presentation-buffer
401
;; when using presentation buffer we have to
403
(set-buffer presentation-buffer)
404
(goto-char (point-min))
405
(search-forward-regexp "\n\n")
406
(setq tstart (match-end 0)
408
(setq presentation-buffer folder-buffer))
410
(insert-buffer-substring presentation-buffer tstart tend)
411
;; in order to show headers hidden by vm-shrunken-headers
412
(put-text-property (point-min) (point-max) 'invisible nil)
414
;; and add the buttons for attachments
415
(vm-decode-postponed-mime-message)))
417
(run-hooks 'vm-mail-hook)
418
(run-hooks 'vm-mail-mode-hook))
419
(run-hooks 'vm-continue-postponed-message-hook))
421
;;-----------------------------------------------------------------------------
422
(defun vm-delete-postponed-message ()
423
"Delete the source message belonging to the continued composition."
425
(if vm-message-pointer
427
(let* ((msg (car vm-message-pointer))
428
(buffer (vm-buffer-of msg)))
429
;; only delete messages which have been postponed by us before
430
(when (vm-get-header-contents msg vm-postponed-header)
431
(vm-set-deleted-flag msg t)
432
(vm-update-summary-and-mode-line))
433
;; in the postponded folder expunge them right now
434
(when (string= (buffer-name buffer)
435
(file-name-nondirectory vm-postponed-folder))
436
(if (frames-of-buffer buffer t)
437
(iconify-frame (car (frames-of-buffer buffer))))
439
(switch-to-buffer buffer)
442
(when (not vm-message-list)
443
(let ((this-command 'vm-quit))
445
(error "Folder buffer closed before deletion of source message."))))
447
;;-----------------------------------------------------------------------------
448
(defun vm-decode-postponed-mime-message ()
449
"Replace the mime buttons by attachment buttons."
452
(let ((e-list (extent-list nil (point-min) (point-max))))
453
;; First collect the extents
456
(function (lambda (e)
457
(extent-property e 'vm-mime-layout)))
459
(function (lambda (e1 e2)
460
(< (extent-end-position e1)
461
(extent-end-position e2))))))
462
;; Then replace the buttons, because doing it at once will result in
463
;; problems since the new buttons are from the same extent.
465
(vm-decode-postponed-mime-button (car e-list))
466
(setq e-list (cdr e-list)))))
468
(let ((o-list (vm-mime-fake-attachment-overlays (point-min)
470
(setq o-list (sort (vm-delete
471
(function (lambda (o)
472
(overlay-get o 'vm-mime-layout)))
477
(overlay-end e2))))))
479
(vm-decode-postponed-mime-button (car o-list))
480
(setq o-list (cdr o-list)))))
482
(error "don't know how to MIME dencode composition for %s"
485
;;-----------------------------------------------------------------------------
486
(defun vm-decode-postponed-mime-button (x)
487
"Replace the mime button specified by X."
495
(setq layout (overlay-get x 'vm-mime-layout)
496
xstart (overlay-start x)
497
xend (overlay-end x))
498
(setq layout (extent-property x 'vm-mime-layout)
499
xstart (extent-start-position x)
500
xend (extent-end-position x)))
502
(let* ((start (vm-mm-layout-header-start layout))
503
(end (vm-mm-layout-body-end layout))
504
(b (marker-buffer start))
505
(desc (or (vm-mm-layout-description layout)
506
"message body text"))
507
(disp (or (vm-mm-layout-disposition layout)
509
(file (vm-mime-get-disposition-parameter layout "filename"))
511
(type (vm-mm-layout-type layout)))
514
(string= (car type) "message/external-body")
515
(string= (cadr type) "access-type=local-file"))
517
(setq filename (substring (caddr type) 5))
518
(vm-select-folder-buffer)
520
(let ((start (vm-mm-layout-body-start layout))
521
(end (vm-mm-layout-body-end layout)))
522
(set-buffer (marker-buffer (vm-mm-layout-body-start layout)))
525
(if (not (re-search-forward
526
"Content-Type: \"?\\([^ ;\" \n\t]+\\)\"?;?"
528
(error "No `Content-Type' header found in: %s"
529
(buffer-substring start end))
530
(setq type (list (match-string 1))))))))
532
;; delete the mime-button
534
(delete-region xstart xend)
535
;; and insert an attached-object-button
537
(vm-mime-attach-file filename (car type))
539
(vm-mime-attach-object (list b start end disp file)
540
(car type) nil desc t)
541
(vm-mime-attach-object (list b start end disp)
542
(car type) nil desc t)))))))
544
;;-----------------------------------------------------------------------------
545
(define-key vm-mail-mode-map [(control c) (control p)] 'vm-postpone-message)
547
;;-----------------------------------------------------------------------------
549
(defun vm-postpone-message (&optional folder dont-kill no-postpone-header)
550
"Save the current composition as a draft.
551
Before saving the composition the `vm-postpone-message-hook' functions
552
are executed and it is written into the FOLDER `vm-postponed-folder'.
553
When called with a prefix argument you will be asked for
555
Optional argument DONT-KILL is positive, then do not kill source message."
558
(let ((message-buffer (current-buffer))
562
(if (and (boundp 'font-lock-mode) font-lock-mode)
564
(if (and vm-fsfemacs-p (boundp 'ispell-minor-mode) ispell-minor-mode)
565
(ispell-minor-mode 0))
566
(if (and vm-fsfemacs-p (boundp 'filladapt-mode) filladapt-mode)
568
(if (boundp 'auto-fill-mode)
571
(if (and folder (not (stringp folder)))
572
(setq folder (vm-read-file-name
573
(format "Postpone to folder (%s): " vm-postponed-folder)
574
(or vm-folder-directory default-directory)
575
vm-postponed-folder nil nil
576
'vm-folder-history)))
578
;; there is no explicit folder given ...
580
(if vm-postponed-message-folder-buffer
581
(setq folder (buffer-file-name vm-postponed-message-folder-buffer))
582
(setq folder (expand-file-name vm-postponed-folder
583
(or vm-folder-directory
584
default-directory)))))
587
(error "I could not find a folder for postponing messages!"))
589
;; if it is no absolute folder path then prepend the folder directory
590
(if (not (file-name-absolute-p folder))
591
(setq folder (expand-file-name folder
592
(or vm-folder-directory
593
default-directory))))
595
;; Now add possibly missing headers
596
(goto-char (point-min))
597
(if (not (vm-mail-mode-get-header-contents "From:"))
598
(let* ((login user-mail-address)
599
(fullname (user-full-name)))
600
(cond ((and (eq mail-from-style 'angles) login fullname)
601
(insert (format "From: %s <%s>\n" fullname login)))
602
((and (eq mail-from-style 'parens) login fullname)
603
(insert (format "From: %s (%s)\n" login fullname)))
605
(insert (format "From: %s\n" login))))))
606
(if (not (vm-mail-mode-get-header-contents "Date:"))
608
(format-time-string "%a, %d %b %Y %H%M%S %Z"
612
;; mime-encode the message if necessary
613
(let ((vm-do-fcc-before-mime-encode nil))
614
(condition-case nil (vm-mime-encode-composition) (error t)))
616
;; add the postponed header
617
(vm-mail-mode-remove-header vm-postponed-header)
619
(if no-postpone-header nil
620
(insert vm-postponed-header " "
622
"(\"%s\" %S %S %S)\n"
623
(format-time-string "%a, %d %b %Y %T %Z" (current-time))
624
(vm-get-persistent-message-ids-for vm-reply-list)
625
(vm-get-persistent-message-ids-for vm-forward-list)
626
(vm-get-persistent-message-ids-for vm-redistribute-list))))
628
;; ensure that the message ends with an empty line!
629
(goto-char (point-max))
630
(skip-chars-backward " \t\n")
631
(delete-region (point) (point-max))
635
(run-hooks 'vm-postpone-message-hook)
637
;; delete mail header separator
638
(beginning-of-buffer)
639
(if (re-search-forward (regexp-quote mail-header-separator) nil t)
640
(delete-region (match-beginning 0) (match-end 0)))
643
(setq folder-buffer (vm-get-file-buffer folder))
645
;; o.k. the folder is already opened
647
(set-buffer folder-buffer)
648
(vm-error-if-folder-read-only)
649
(let ((buffer-read-only nil))
652
(goto-char (point-max))
653
(vm-write-string (current-buffer) (vm-leading-message-separator))
654
(insert-buffer-substring message-buffer)
655
(vm-write-string (current-buffer) (vm-trailing-message-separator))
657
(cond ((eq major-mode 'vm-mode)
658
(vm-increment vm-messages-not-on-disk)
659
(vm-clear-modification-flag-undos)))
661
(vm-check-for-killed-summary)
662
(vm-assimilate-new-messages)
663
(vm-update-summary-and-mode-line))))
664
;; well the folder is not visited, so we write to the file
665
(setq target-type (or (vm-get-folder-type folder)
666
vm-default-folder-type))
668
(if (eq target-type 'unknown)
669
(error "Folder `%s' type is unrecognized" folder))
671
(vm-write-string folder (vm-leading-message-separator target-type))
672
(write-region (point-min) (point-max) folder t 'quiet)
673
(vm-write-string folder (vm-trailing-message-separator target-type)))
675
;; delete source message
676
(vm-delete-postponed-message)
678
;; mess arounf with the window configuration
679
(let ((b (current-buffer))
680
(this-command 'vm-mail-send-and-exit))
681
(cond ((null (buffer-name b));; dead buffer
682
;; This improves window configuration behavior in
683
;; XEmacs. It avoids taking the folder buffer from
684
;; one frame and attaching it to the selected frame.
685
(set-buffer (window-buffer (selected-window)))
686
(vm-display nil nil '(vm-mail-send-and-exit)
687
'(vm-mail-send-and-exit
691
(vm-display b nil '(vm-mail-send-and-exit)
692
'(vm-mail-send-and-exit reading-message startup)))))
694
;; and kill this buffer?
696
(insert (concat "FCC: " folder "\n" mail-header-separator))
700
(message "Message postponed to folder `%s'" folder))))
702
;;-----------------------------------------------------------------------------
703
(defun vm-buffer-in-vm-mode ()
704
(member major-mode '(vm-mode vm-virtual-mode
709
(defcustom vm-continue-what-message 'ask
710
"Whether to never continue, ask or always continue postponed messages."
711
:type '(choice (const :tag "never" nil)
716
(defun vm-continue-what-message-composing ()
717
"Decide whether to compose a new message or continue a draft.
718
This checks if the postponed folder contains drafts.
719
Drafts in other folders are not recognized!"
721
(vm-session-initialization)
723
(let* ((ppfolder (and vm-postponed-folder
724
(expand-file-name vm-postponed-folder
725
(or vm-folder-directory
726
default-directory))))
730
;; postponed message in current folder
731
(when (vm-buffer-in-vm-mode)
732
(vm-check-for-killed-folder)
733
(vm-select-folder-buffer)
735
(if (and vm-message-pointer
736
(vm-get-header-contents (vm-real-message-of
737
(car vm-message-pointer))
738
(regexp-quote vm-postponed-header))
739
(not (vm-deleted-flag (car vm-message-pointer))))
740
(setq action 'continue)))
742
;; postponed message in postponed folder
743
(when (and (not action) (setq buffer (vm-get-file-buffer ppfolder)))
744
(if (and (get-buffer-window-list buffer nil 0))
745
(when (save-excursion
747
(not (vm-deleted-flag (car vm-message-pointer))))
748
(message "Please select a draft!")
749
(select-window (car (get-buffer-window-list buffer nil 0)))
750
(if (frames-of-buffer buffer)
751
(deiconify-frame (car (frames-of-buffer buffer))))
753
(setq action 'visit)))
755
;; visit postponed folder
756
(when (and (not action) (file-exists-p ppfolder)
757
(> (nth 7 (file-attributes ppfolder)) 0))
758
(setq action 'visit))
760
(if (not action) (setq action 'new))
764
(cond ((eq vm-continue-what-message nil)
766
((eq vm-continue-what-message 'ask)
767
(if (equal action 'visit)
769
"Continue composition of postponed messages? ")
773
((eq vm-continue-what-message 'continue)
779
(defun vm-continue-what-message (&optional where)
780
"Ask for continuing of postponed messages if there are some."
782
(if where (setq where (concat "-" where)))
783
(let ((action (vm-continue-what-message-composing))
784
(visit (intern (concat "vm-visit-folder" (or where ""))))
785
(mail (intern (concat "vm-mail" (or where "")))))
786
(cond ((equal action 'continue)
787
(vm-continue-postponed-message))
788
((equal action 'visit)
789
(funcall visit vm-postponed-folder)
790
(vm-select-folder-buffer)
791
(make-local-hook 'vm-quit-hook)
792
(add-hook 'vm-quit-hook 'vm-expunge-folder)
794
(cond ((= (length vm-message-list) 0)
795
(let ((this-command 'vm-quit))
797
(let ((this-command mail))
799
((= (length vm-message-list) 1)
800
(vm-continue-postponed-message))))
802
(let ((this-command mail))
806
(defun vm-continue-what-message-other-window ()
807
"Ask for continuing of postponed messages if there are some."
809
(vm-continue-what-message "other-window"))
812
(defun vm-continue-what-message-other-frame ()
813
"Ask for continuing of postponed messages if there are some."
815
(vm-continue-what-message "other-frame"))
817
;;-----------------------------------------------------------------------------
818
;; And now do some cool stuff when killing a mail buffer
819
;; This was inspired by Uwe Brauer
820
(defcustom vm-save-killed-message
822
"How `vm-save-killed-message-hook' handles saving of a mail as a draft.
823
If set to 'ask it will ask whether to save the mail as draft or not.
824
If set to 'always it will save without asking.
825
If set to nil it will never save them nor it will ask."
826
:type '(choice (const ask)
828
(const :tag "never" nil))
831
(defcustom vm-save-killed-messages-folder
833
"The name of the folder where killed messages are saved."
837
(defun vm-add-save-killed-message-hook ()
838
(make-local-hook 'kill-buffer-hook)
839
(add-hook 'kill-buffer-hook 'vm-save-killed-message-hook nil t))
841
(defun vm-remove-save-killed-message-hook ()
842
(remove-hook 'kill-buffer-hook 'vm-save-killed-message-hook t))
844
(defun vm-save-killed-message-hook ()
845
(if (or (and (equal vm-save-killed-message 'ask)
846
(y-or-n-p (format "Save `%s' as draft in folder `%s'? "
848
vm-save-killed-messages-folder)))
849
(equal vm-save-killed-message 'always))
850
(vm-postpone-message vm-save-killed-messages-folder t)
851
(message "`%s' is gone forever!" (buffer-name))))
853
(add-hook 'vm-mail-mode-hook 'vm-add-save-killed-message-hook)
854
(add-hook 'mail-send-hook 'vm-remove-save-killed-message-hook)
855
(add-hook 'vm-postpone-message-hook 'vm-remove-save-killed-message-hook)
857
;;-----------------------------------------------------------------------------
859
(define-key vm-mail-mode-map "\C-c\C-f\C-a" 'vm-mail-return-receipt-to)
860
(define-key vm-mail-mode-map "\C-c\C-f\C-p" 'vm-mail-priority)
861
(define-key vm-mail-mode-map "\C-c\C-f\C-f" 'vm-mail-fcc)
862
(define-key vm-mail-mode-map "\C-c\C-f\C-n" 'vm-mail-notice-requested-upon-delivery-to)
865
(defcustom vm-mail-return-receipt-to
866
(concat (user-full-name) " <" user-mail-address ">")
867
"The address where return receipts should be sent to."
872
(defun vm-mail-return-receipt-to ()
873
"Insert the \"Return-Receipt-To\" header into a `vm-mail-mode' buffer.
874
See the variable `vm-mail-return-receipt-to'."
878
(or (mail-position-on-field "Return-Receipt-To" t)
879
(progn (mail-position-on-field "Subject")
880
(insert "\nReturn-Receipt-To: " vm-mail-return-receipt-to
881
"\nRead-Receipt-To: " vm-mail-return-receipt-to
882
"\nDelivery-Receipt-To: " vm-mail-return-receipt-to))))
883
(message "Remove those headers you do not require!"))
886
(defun vm-mail-notice-requested-upon-delivery-to ()
887
"Notice-Requested-Upon-Delivery-To:"
891
(or (mail-position-on-field "Notice-Requested-Upon-Delivery-To" t)
892
(progn (mail-position-on-field "Subject")
893
(insert "\nNotice-Requested-Upon-Delivery-To: "
894
(let ((to (vm-mail-get-header-contents
899
(defcustom vm-mail-priority
900
"Priority: urgent\nImportance: High\nX-Priority: 1"
901
"The priority headers."
906
(defun vm-mail-priority ()
907
"Insert priority headers into a `vm-mail-mode' buffer.
908
See the variable `vm-mail-priority'."
912
(or (mail-position-on-field "Priority" t)
913
(progn (mail-position-on-field "Subject")
914
(insert "\n" vm-mail-priority)))))
916
;;-----------------------------------------------------------------------------
917
(if (not vm-xemacs-p)
918
(defun user-home-directory ()
921
(defun vm-mail-fcc-file-join (dir file)
922
"Returns a nice path to a folder."
923
(let* ((path (expand-file-name file dir)))
925
(if (not vm-xemacs-p)
926
(abbreviate-file-name path)
927
(abbreviate-file-name path t))
931
(defcustom vm-mail-folder-alist vm-auto-folder-alist
932
"Like `vm-auto-folder-alist' but for outgoing messages.
933
It should be fed to `vm-mail-select-folder'!"
938
(defcustom vm-mail-fcc-default
939
'(or (vm-mail-select-folder vm-mail-folder-alist)
940
(vm-mail-to-fcc nil t)
941
mail-archive-file-name)
942
"A list which is evaluated to return a folder name.
943
By reordering the elements of this list or adding own functions you
944
can control the behavior of vm-mail-fcc and `vm-mail-auto-fcc'.
945
You may allow a sophisticated decision for the right folder for your
951
(defun vm-mail-fcc (&optional arg)
952
"Insert the FCC-header into a `vm-mail-mode' buffer.
953
Like `mail-fcc', but honors VM variables and offers a default folder
954
according to `vm-mail-folder-alist'.
955
Called with prefix ARG it just removes the FCC-header."
959
(let ((dir (or vm-folder-directory default-directory))
961
(folder (vm-mail-mode-get-header-contents "FCC:"))
964
(if arg (progn (vm-mail-mode-remove-header "FCC:")
965
(message "FCC header removed!"))
967
(setq fcc (eval vm-mail-fcc-default))
970
(setq fcc (if fcc (vm-mail-fcc-file-join dir fcc)))
973
(format "FCC to folder (%s): " fcc)
976
(setq folder (if (and folder (not (file-directory-p folder)))
977
(file-relative-name folder dir)))
979
;; we got the name so insert it
980
(vm-mail-mode-remove-header "FCC:")
981
(setq fcc (vm-read-file-name prompt
985
(setq fcc (vm-mail-fcc-file-join dir fcc))
986
(if (file-directory-p fcc)
987
(error "Folder `%s' in no file, but a directory!" fcc)
988
(mail-position-on-field "FCC")
992
(defun vm-mail-auto-fcc ()
993
"Add a new FCC field, with file name guessed by `vm-mail-folder-alist'.
994
You likely want to add it to `vm-reply-hook' by
995
(add-hook 'vm-reply-hook 'vm-mail-auto-fcc)
996
or if sure about what you are doing you can add it to mail-send-hook!"
1000
(let ((dir (or vm-folder-directory default-directory))
1003
(vm-mail-mode-remove-header "FCC:")
1004
(setq fcc (eval vm-mail-fcc-default))
1006
(if (file-directory-p fcc)
1007
(error "Folder `%s' in no file, but a directory!" fcc)
1008
(progn (mail-position-on-field "FCC")
1009
(insert (vm-mail-fcc-file-join dir fcc))))))))
1012
(defun vm-mail-get-header-contents (header-name-regexp &optional clump-sep)
1013
"Return the contents of the header(s) matching HEADER-NAME-REGEXP.
1014
This function is a slightly changed version of `vm-get-header-contents'.
1015
Optional argument CLUMP-SEP usually a \",\"."
1016
(let ((contents nil)
1018
(regexp (concat "^\\(" header-name-regexp "\\)")))
1020
(goto-char (point-min))
1021
(if (re-search-forward (regexp-quote mail-header-separator)
1023
(setq text-of-message (match-end 0))
1024
(error "No mail header separator found!"))
1026
(goto-char (point-min))
1027
(let ((case-fold-search t))
1028
(while (and (or (null contents) clump-sep)
1029
(re-search-forward regexp text-of-message t)
1030
(save-excursion (goto-char (match-beginning 0))
1034
(concat contents clump-sep (vm-matched-header-contents)))
1035
(setq contents (vm-matched-header-contents)))))
1039
(defun vm-mail-select-folder (folder-alist)
1040
"Return a folder according to FOLDER-ALIST for the current message.
1041
This function is a slightly changed version of `vm-auto-select-folder'."
1043
(condition-case error-data
1045
(let (header tuple-list)
1047
(setq header (vm-mail-get-header-contents
1048
(car (car folder-alist)) ", "))
1051
(setq tuple-list (cdr (car folder-alist)))
1053
(if (let ((case-fold-search vm-auto-folder-case-fold-search))
1054
(string-match (car (car tuple-list)) header))
1055
;; Don't waste time eval'ing an atom.
1056
(if (stringp (cdr (car tuple-list)))
1057
(throw 'match (cdr (car tuple-list)))
1058
(let* ((match-data (vm-match-data))
1059
;; allow this buffer to live forever
1060
(buf (get-buffer-create " *vm-auto-folder*"))
1062
;; Set up a buffer that matches our cached
1066
(if vm-fsfemacs-mule-p
1067
(set-buffer-multibyte nil))
1071
;; It appears that get-buffer-create clobbers the
1074
;; The match data is off by one because we matched
1075
;; a string and Emacs indexes strings from 0 and
1078
;; Also store-match-data only accepts MARKERS!!
1082
(function (lambda (n) (and n (vm-marker n))))
1084
(function (lambda (n) (and n (1+ n))))
1086
(setq result (eval (cdr (car tuple-list))))
1087
(while (consp result)
1088
(setq result (vm-mail-select-folder result)))
1090
(throw 'match result))))))
1091
(setq tuple-list (cdr tuple-list))))
1092
(setq folder-alist (cdr folder-alist)))
1094
(error "Error processing folder-alist: %s"
1095
(prin1-to-string error-data))))
1098
(defcustom vm-mail-to-regexp "\\([^<\t\n ]+\\)@"
1099
"A regexp matching the part of an email address to use as FCC-folder.
1100
The string enclosed in \"\\\\(\\\\)\" is used as folder name."
1105
(defcustom vm-mail-to-headers '("To:" "CC:" "BCC:")
1106
"A list of headers for finding the email address to use as FCC-folder."
1107
:type '(repeat (string))
1111
(defun vm-mail-to-fcc (&optional arg return-only)
1112
"Insert a FCC-header into a `vm-mail-mode' buffer.
1113
Like `mail-fcc', but honors VM variables and inserts the first email
1114
address (or the like matched by `vm-mail-to-regexp') found in the headers
1115
listed in `vm-mail-to-headers'.
1116
Called with prefix ARG it just removes the FCC-header.
1117
If optional argument RETURN-ONLY is t just returns FCC."
1121
(headers vm-mail-to-headers))
1122
(if arg (progn (vm-mail-mode-remove-header "FCC:")
1123
(message "FCC header removed!"))
1125
(while (and (not fcc) headers)
1126
(setq fcc (vm-mail-get-header-contents (car headers)))
1127
(if (and fcc (string-match vm-mail-to-regexp fcc))
1128
(setq fcc (match-string 1 fcc))
1130
(setq headers (cdr headers)))
1131
(setq fcc (or fcc mail-archive-file-name))
1135
(if (file-directory-p fcc)
1136
(error "Folder `%s' in no file, but a directory!" fcc)
1137
(vm-mail-mode-remove-header "FCC:")
1138
(mail-position-on-field "FCC")
1139
(insert (vm-mail-fcc-file-join (or vm-folder-directory
1143
;;-----------------------------------------------------------------------------
1146
;;; vm-pine.el ends here