1 ;; -*- mode: Emacs-Lisp; mode: rainbow; -*-
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;; This program is free software: you can redistribute it and/or modify ;;
5 ;; it under the terms of the version 3 of the GNU General Public License ;;
6 ;; as published by the Free Software Foundation. ;;
8 ;; This program is distributed in the hope that it will be useful, but ;;
9 ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;
10 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;
11 ;; General Public License for more details. ;;
13 ;; You should have received a copy of the GNU General Public License ;;
14 ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;
16 ;; Written by and Copyright (C) Francois Fleuret ;;
17 ;; Contact <francois@fleuret.org> for comments & bug reports ;;
18 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; A fast indexed / search in mbox
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;; This is one of my own things, check my web page to get it
25 (when (ff/load-or-alert "~/sources/gpl/mymail/mymail-vm.el")
27 (define-key vm-summary-mode-map "\\" 'mymail/vm-visit-folder)
28 (define-key global-map [S-f7] 'mymail/vm-visit-folder)
29 (setq mymail/default-search-request "today"
30 mymail/default-additional-search-requests "!s ^\\[SPAM\\],!s \\] STATUS,")
31 (add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox")
34 (setq-default vm-summary-show-threads t)
36 ;; (setq vm-preview-lines nil)
38 ;; (setq vm-auto-displayed-mime-content-types '("text"));; "multipart"));; "image/xpm"
40 (setq vm-mime-thumbnail-max-geometry nil)
42 (setq vm-auto-displayed-mime-content-types '(
52 ;; browse-url-mozilla-program "iceweasel"
53 ;; mail-complete-style nil
54 ;; mail-from-style nil
55 ;; vm-coding-system-priorities '(utf-8)
56 ;; vm-highlighted-header-regexp "From:\\|Subject:\\|Cc:\\|To:\\|Bcc:\\|Reply-To:"
57 ;; vm-included-text-attribution-format "\nOn %w, %m %d, at %H, you wrote:\n\n"
58 ;; vm-jump-to-new-messages nil
59 ;; vm-mime-7bit-composition-charset "latin-1"
60 ;; vm-mime-8bit-composition-charset "utf-8"
61 ;; vm-preview-read-messages t
62 ;; vm-summary-format " %*%A %-3.3m %2d %5US %I%UA %s\n"
63 ;; vm-summary-uninteresting-senders-arrow "->"
64 ;; vm-summary-uninteresting-senders-arrow "►"
65 ;; vm-summary-uninteresting-senders-arrow "➔"
66 ;; vm-summary-uninteresting-senders-arrow "➤"
67 bbdb-send-mail-style 'vm
68 bbdb/mail-auto-create-p nil
70 mail-specify-envelope-from t
71 vm-auto-folder-case-fold-search t
72 vm-auto-get-new-mail t
73 vm-circular-folders nil
74 vm-confirm-new-folders t
75 vm-delete-after-archiving t
76 vm-delete-after-saving t
77 vm-forwarding-digest-type "mime"
78 vm-forwarding-subject-format "(forwarded from %F) %s"
79 vm-frame-per-folder nil
80 vm-frame-per-summary nil
81 vm-highlighted-header-regexp "From:\\|Subject:\\|Reply-To:"
82 vm-in-reply-to-format nil
83 vm-included-text-attribution-format "\nOn %w, %m %d, %y (%h), %F wrote:\n\n"
84 vm-included-text-prefix " > "
85 vm-keep-sent-messages nil
86 vm-mime-8bit-composition-charset "iso-8859-1"
87 vm-mime-attachment-save-directory "~/misc/attachments"
88 vm-mime-yank-attachments nil
91 vm-netscape-program browse-url-mozilla-program
93 vm-reply-subject-prefix "Re: "
94 vm-skip-deleted-messages nil
95 vm-skip-read-messages nil
96 vm-startup-message-displayed t
97 vm-startup-with-summary t
99 vm-summary-format " %*%a %-3.3m %2d %5US %I%UA %s\n"
100 vm-summary-thread-indent-level 1
101 vm-summary-uninteresting-senders-arrow ">"
107 ;; (add-to-list 'vm-visible-headers "From " t)
108 (add-to-list 'vm-visible-headers "Reply-To:" t)
109 ;; (add-to-list 'vm-visible-headers "X-Mailer:" t)
110 ;; (add-to-list 'vm-visible-headers "X-from-in-bbdb:" t)
111 ;; (add-to-list 'vm-visible-headers "Return-Path:")
113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 ;; Mime-related stuff
118 vm-infer-mime-types t
119 vm-mime-use-image-strips nil
120 vm-mime-base64-decoder-program "base64"
121 vm-mime-base64-decoder-switches '("-d")
122 vm-mime-base64-encoder-program "base64"
123 vm-mime-base64-encoder-switches '()
125 vm-mime-internal-content-types '(
133 ;; To force it to be converted to plain text
134 ;; vm-mime-internal-content-type-exceptions '("text/html")
136 vm-mime-external-content-types-alist '(
137 ("application/x-dvi" "xdvi")
138 ("image/postscript" "gv")
139 ("application/pdf" "xpdf")
140 ("application/postscript" "gv")
143 ;; ("text/html" "firefox")
144 ;; ("application/pdf" "epdfview")
149 (require 'vm-rfaddons)
151 ;; The two following lines deal with windows-1252 buggy encoding
153 ;;**;; ;; First, don't display iso-8859-1 as-is in default face
154 ;;**;; (delete "iso-8859-1" vm-mime-default-face-charsets)
155 ;;**;; ;; Then substitute windows-1252 for iso-8859-1
156 ;;**;; (add-to-list 'vm-mime-mule-charset-to-coding-alist '("iso-8859-1" windows-1252))
158 ;; (setq vm-mime-default-face-charsets t)
160 ;; (add-to-list 'vm-mime-default-face-charsets "utf-8")
162 ;; (add-to-list 'vm-mime-default-face-charsets "iso-8859-1")
163 ;; (add-to-list 'vm-mime-default-face-charsets "Windows-1251")
164 ;; (add-hook 'vm-mail-send-hook 'ff/vm-remove-non-7bits-in-headers)
165 (add-hook 'vm-mail-send-hook 'vm-mime-encode-headers)
166 (add-hook 'vm-mail-send-hook 'vm-mail-check-recipients)
167 (add-hook 'vm-reply-hook (lambda () (set-buffer-modified-p nil)))
169 (add-to-list 'vm-mime-attachment-auto-type-alist '(".*" . "application/octet-stream") t)
171 ;; (add-to-list 'vm-mime-type-converter-alist '("text/html" "text/plain" "cat"))
172 ;; (add-to-list 'vm-mime-type-converter-alist '("text/html" "text/plain" "lynx -nolist -force_html -dump -stdin"))
174 ;; (add-to-list 'vm-mime-type-converter-alist
175 ;; '("text/html" "text/plain"
176 ;; "w3m -cols 75 -graph -dump -T text/html"
179 ;; (add-to-list 'vm-mime-type-converter-alist
180 ;; '("text/html" "text/plain"
181 ;; "html2text -style pretty -nobs"
184 ;; (add-to-list 'vm-mime-type-converter-alist
185 ;; '("text/html" "text/plain"
189 (add-to-list 'vm-mime-type-converter-alist
190 '("image" "image/xpm"
191 "/usr/bin/convert -geometry 640x480 - xpm:-"))
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; (defun ff/vm-remove-properties () (interactive)
197 ;; (goto-char (point-min))
198 ;; (re-search-forward (concat "^" mail-header-separator "$"))
199 ;; (set-text-properties (point) (point-max) nil)
203 ;; (add-hook 'vm-mail-send-hook 'ff/vm-remove-properties)
205 ;; (defun ff/vm-mime-save-all-files (&optional delete)
206 ;; "Save all the mail attachments. With delete argument, remove
207 ;; the attachement from mail."
209 ;; (let ((vm-mime-delete-after-saving delete))
210 ;; (while (and (vm-mime-reader-map-save-file)
211 ;; (condition-case nil (vm-move-to-next-button 1)
215 (defun ff/vm-mime-save-file (&optional delete)
216 "Save the current attachement. With delete argument, remove the
217 attachement from mail."
219 (let ((vm-mime-delete-after-saving delete))
220 (vm-mime-reader-map-save-file))
221 (condition-case nil (vm-move-to-next-button 1) (error (message "No more attachment"))))
223 ;; (define-key vm-summary-mode-map [(r)] 'vm-reply-include-text)
224 ;; (define-key vm-summary-mode-map [(R)] 'vm-followup-include-text)
226 (define-key vm-summary-mode-map [(control o)] 'ff/vm-mime-save-file)
228 (define-key vm-summary-mode-map [(control t)]
229 (lambda () (interactive)
230 (vm-toggle-threads-display)
231 (unless vm-summary-show-threads
232 (vm-sort-messages "date"))))
234 (defun ff/vm-select-thread-for-next-command () (interactive)
235 (vm-mark-thread-subtree)
236 (vm-next-command-uses-marks))
238 (define-key vm-summary-mode-map "T" 'ff/vm-select-thread-for-next-command)
240 (defun ff/vm-attach-file-or-dir
242 "Attaches the file or recursively the content of the directory with
243 `vm-mime-attach-file'."
244 (interactive "fFile or directory: ")
247 (goto-char (point-max))
249 (if (file-regular-p dir)
250 (vm-mime-attach-file dir (vm-mime-default-type-from-filename dir))
251 (if (file-directory-p dir)
254 (when (not (string-match "^\\." (car x)))
255 (ff/vm-attach-file-or-dir
257 (unless (string-match "/$" dir) "/")
259 (directory-files-and-attributes dir)
262 (error "Can attach only files and directories")
265 (define-key vm-mail-mode-map [(control c) (control a)] 'ff/vm-attach-file-or-dir)
267 ;; Found no other way to avoid displaying the icones
269 (defun vm-mime-set-image-stamp-for-type (e type))
271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
274 (defun vm-summary-function-A (message)
275 (let* ((from (vm-su-from message)))
276 (if (string-match vm-summary-uninteresting-senders from)
277 (concat vm-summary-uninteresting-senders-arrow " " (ff/explicit-name (vm-su-to message)))
278 (ff/explicit-name from))))
280 (defun vm-summary-function-S (&optional message)
281 (let ((s (string-to-int (vm-su-byte-count message))))
283 (propertize (concat (int-to-string (/ s 1024)) "k")
288 (defun ff/vm-delete-and-go-down () (interactive)
290 (vm-delete-message 1)
291 (condition-case nil (vm-next-message-no-skip 1) (error nil)))
293 (defun ff/vm-expunge-folder ()
294 (unless vm-folder-read-only (vm-expunge-folder)))
296 (add-hook 'vm-quit-hook 'ff/vm-expunge-folder)
297 (add-hook 'vm-quit-hook 'bbdb-save-db)
298 (add-hook 'vm-retrieved-spooled-mail-hook 'display-time-update)
300 (ff/configure-faces '((ff/summary-highlight-face :background "yellow"
304 (setq vm-summary-highlight-face 'ff/summary-highlight-face)
306 (define-key vm-summary-mode-map [(K)] 'ff/vm-delete-and-go-down)
308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
309 ;; Activate the required modes and authorize the commenting
311 (defun ff/prepare-mail-mode ()
312 (bbdb-define-all-aliases)
318 ;; (setq fill-paragraph-function 'mail-mode-fill-paragraph)
320 ;; Since I set the comment prefix, I have to tell the filling
321 ;; functions not to use it
323 ;; ******************* removed Aug 23
324 ;; (setq fill-paragraph-handle-comment nil)
325 ;; ;; (when message-yank-prefix
326 (set (make-local-variable 'comment-start) vm-included-text-prefix)
327 ;; (set (make-local-variable 'comment-start-skip)
328 ;; (concat "^\\(" (regexp-quote vm-included-text-prefix) "\\)"))
332 (add-hook 'mail-mode-hook 'ff/prepare-mail-mode)
333 ;; (add-hook 'mail-mode-hook 'orgtbl-mode)
335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
336 ;; To have a slightly darker background for headers
339 ;; '((ff/mail-header-face :background "#c8c8ff"))
340 '((ff/mail-header-face :foreground "blue4"))
343 (defun ff/colorize-headers () (interactive)
344 (let ((inhibit-read-only t))
346 (goto-char (point-min))
347 (while (vm-match-header)
348 (goto-char (vm-matched-header-end)))
350 ;; (vm-matched-header-contents-start)
351 ;; (vm-matched-header-contents-end)
354 '(face ff/mail-header-face)
358 (defadvice vm-highlight-headers (after ff/colorize-headers nil activate)
359 (ff/colorize-headers))
361 (defun ff/highlight-important-words ()
362 (let ((inhibit-read-only t))
364 (goto-char (point-min))
365 (while (re-search-forward "Fleuret" nil t)
366 (message "%d-%d" (match-beginning 0) (match-end 0))
367 ;; (add-text-properties (match-beginning 0) (match-end 0)
368 ;; '(face (:background "red"))
373 ;; (add-hook 'vm-select-message-hook 'ff/highlight-important-words)
375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 ;; I want to have a file associated to every mail I am writing
378 (defcustom ff/vm-mail-draft-directory "~/"
379 "Where to save mail drafts with VM")
381 (defun ff/associate-file-to-vm-mail-buffer ()
382 "Associate the current buffer to a file whose name is built from the current time."
383 (unless (buffer-file-name)
384 (set-visited-file-name (format
386 ff/vm-mail-draft-directory
388 "%04Y%02m%02d-%02H%02M%02S"
390 (set-buffer-modified-p nil)))
392 (add-hook 'mail-setup-hook 'ff/associate-file-to-vm-mail-buffer)
394 (defun ff/mail-header-field (field) (interactive)
395 "Grab the value of a certain field from the mail header."
396 (let ((s "no-subject"))
398 (goto-char (point-min))
399 (let ((l (re-search-forward (concat "^" mail-header-separator "$") nil t)))
401 (goto-char (point-min))
402 (when (re-search-forward (concat "^" field ": ") l t nil)
403 (setq s (buffer-substring-no-properties (point) (point-at-eol))))
409 (defun ff/dissociate-file-from-vm-mail-buffer ()
410 "Save the file under a new name and set the associated file to nil."
411 (let ((bn (buffer-file-name)))
413 (set-visited-file-name
414 (concat (file-name-directory bn)
416 (file-name-nondirectory bn)
418 (replace-regexp-in-string "[^a-zA-Z0-9]+" "_"
419 (ff/mail-header-field "Subject"))
422 (set-visited-file-name nil))
426 (defun ff/find-file-in-vm-mail-mode (filename) (interactive)
427 ;; No easy way to activate vm-mail-mode, so we create such a
428 ;; buffer, erase its content and insert the file
430 (when (file-exists-p filename)
432 (insert-file filename))
433 (set-visited-file-name filename)
434 (set-buffer-modified-p nil)
435 ;; (run-hooks find-file-hooks)
436 (when (functionp 'alarm-vc-check) (alarm-vc-check))
437 ;; Move the cursor at a convenient location
438 (when (re-search-forward (concat "^" mail-header-separator "$") nil t)
439 (if (re-search-forward "^-- $" nil t)
445 ;; All this mess to activate the vm-mail-mode when loading a file
446 ;; looking like a mail draft. Did I miss something ?
448 (defadvice find-file (around ff/find-file-or-mail
449 (filename &optional wildcards)
452 (interactive "FFind file: \np")
454 (if (string-match "^\\(mail\\|sent\\)-[^/]+$"
455 (file-name-nondirectory filename))
457 (if (find-buffer-visiting filename)
458 (switch-to-buffer (find-buffer-visiting filename))
459 (ff/find-file-in-vm-mail-mode filename))
463 (setq ff/vm-mail-draft-directory "~/private/drafts")
465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
466 ;; Check there are no missing attachment (the idea comes from
467 ;; http://home.cc.gatech.edu/eaganj/MailApp) and no leading "From"
468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
470 (defcustom ff/check-vm-attachement-regexp "attach"
471 "*A mail whose body matches this regular expression should contain
474 (defun ff/check-vm-attachment ()
475 (when (save-excursion
476 (goto-char (point-min))
477 (and (re-search-forward "\\[ATTACHMENT" nil t)
478 (not (get-text-property (point) 'vm-mime-object))))
479 (error "Buggy attachment"))
482 (save-excursion (goto-char (point-min))
483 (re-search-forward ff/check-vm-attachement-regexp nil t))
484 (not (save-excursion (goto-char (point-min))
485 (re-search-forward "\\[ATTACHMENT" nil t)))
486 (not (y-or-n-p "An attachment seems to be missing, send message ? ")))
487 (error "You refer to an unexisting attachment."))
491 ;; You can not have a line starting with "From:" in a pure text
492 ;; mail. The smtp server would add a leading character to prevent it.
494 (defun ff/check-no-leading-from ()
495 (and (let ((case-fold-search nil))
497 (goto-char (point-min))
498 (re-search-forward (concat "^" mail-header-separator "$"))
499 (re-search-forward "^From " nil t)))
500 (not (y-or-n-p "There is a leading ``From '', send message ? "))
501 (error "There is a leading ``From ''.")))
503 ;; An attempt at limiting excess wording in sent mails
505 (defface ff/strong-words
506 '((t (:background "red")))
507 "The face to highlight upper caps, exclamation marks and such.")
509 (defun ff/max-in-a-row (overlay regexp max)
510 (let ((case-fold-search nil))
512 (goto-char (point-min))
513 (re-search-forward (concat "^" mail-header-separator "$"))
514 (when (and (re-search-forward regexp nil t nil)
515 (>= (- (match-end 0) (match-beginning 0)) max))
516 (move-overlay overlay (match-beginning 0) (match-end 0))
519 (defun ff/check-no-excess-wording () (interactive)
520 (let ((overlay (make-overlay 0 0)))
521 (overlay-put overlay 'face 'media/current-tune-face)
523 (or (ff/max-in-a-row overlay "[A-Z\?\!][A-Z\?\! ]+[A-Z\?\!]" 6)
524 (ff/max-in-a-row overlay "[\?\!]+" 2)
526 (not (y-or-n-p "That does not look good. Send message ? ")))))
527 (delete-overlay overlay)
528 (when err (error "Good idea. Chill out a bit.")))
531 (defun ff/check-badly-encoded-address () (interactive)
532 (let (bodysep bad-adr)
534 (goto-char (point-min))
535 (search-forward mail-header-separator)
536 (setq bodysep (vm-marker (match-beginning 0)))
537 (goto-char (point-min))
538 (setq bad-adr (re-search-forward "[^<a-zA-Z_0-9\-\. \n\t]+[^ \n]*@" nil t))
539 (when (and bad-adr (< bad-adr bodysep))
540 (error "There is an invalid address in the header (%s)"
544 (add-hook 'vm-mail-send-hook 'ff/check-vm-attachment)
545 (add-hook 'vm-mail-send-hook 'ff/check-no-leading-from)
546 (add-hook 'vm-mail-send-hook 'ff/check-no-excess-wording)
547 (add-hook 'vm-mail-send-hook 'flyspell-mode-off)
549 (defadvice vm-mail-send-and-exit (before ff/switch-flyspell-off nil activate)
552 ;; Append so that it happens after the mime encoding
553 ;; (add-hook 'vm-mail-send-hook 'ff/check-badly-encoded-address t)
555 ;; Append this hook so that it runs after all other checks
556 (add-hook 'vm-mail-send-hook 'ff/dissociate-file-from-vm-mail-buffer t)
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 ;; If we can, encrypt!
561 (add-hook 'vm-mode-hook 'mc-install-read-mode)
562 (add-hook 'vm-summary-mode-hook 'mc-install-read-mode)
563 (add-hook 'vm-virtual-mode-hook 'mc-install-read-mode)
564 (add-hook 'vm-mail-mode-hook 'mc-install-write-mode)
565 (add-hook 'vm-presentation-mode-hook 'mc-install-read-mode)
567 ;; (defun ff/encrypt-mail-if-possible () (interactive)
568 ;; (condition-case nil (mc-encrypt-message)
571 ;; (add-hook 'vm-mail-send-hook 'ff/encrypt-mail-if-possible t)
573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
576 ;; Move through important points in the mail ("To:" field, "Subject:"
577 ;; field and the end of the body)
579 (defun ff/goto-next-mail-field () (interactive)
580 (let ((field (save-excursion
583 (concat "\\(^[a-zA-Z\-]*: \\|^" mail-header-separator "$\\)") nil t)
586 (cond ((string= field "To: ")
588 (re-search-forward "Subject: ")
591 ((string= field "Subject: ")
592 (re-search-forward (concat "^" mail-header-separator "$"))
593 (if (re-search-forward "^-- $" nil t)
598 (t (beginning-of-buffer)
599 (re-search-forward "^To: ")
601 (re-search-forward "^[a-zA-Z\-]*: ")
605 ;; (define-key vm-mail-mode-map [(control tab)] 'ff/goto-next-mail-field)
606 (define-key vm-mail-mode-map [(iso-lefttab)] 'ff/goto-next-mail-field)
607 ;; (define-key vm-mail-mode-map [(shift iso-lefttab)] 'mail-mode-smart-tab)
608 (define-key vm-mail-mode-map [(shift iso-lefttab)] 'bbdb-complete-name)
610 ;; The definition of "\t" is forced through a hook defined in
611 ;; vm-init.el, so I add mine. This is ugly.
613 (add-hook 'mail-setup-hook
614 '(lambda () (local-set-key "\t" 'ff/goto-next-mail-field))
617 (substitute-key-definition 'next-line 'mail-abbrev-next-line vm-mail-mode-map global-map)
619 (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer vm-mail-mode-map global-map)
621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
622 ;; I rarely edit two mails at the same time, and it makes sense to
623 ;; come back to the one currently being edited with the same function
625 (defun ff/first-buffer-in-mode (l m)
627 (if (eq (save-excursion
628 (set-buffer (car l)) major-mode) m)
630 (ff/first-buffer-in-mode (cdr l) m))))
632 (defun ff/compose-mail (&optional force-new)
633 "Cycles through an existing buffers with major mode `mail-mode',
634 or invoke `vm-compose-mail' if none can be found or if FORCE-NEW
637 (when (eq major-mode 'mail-mode) (bury-buffer))
638 (let ((buf (and (not force-new)
639 (ff/first-buffer-in-mode (buffer-list) 'mail-mode))))
640 (if buf (switch-to-buffer buf)
643 (define-key global-map [(control x) (m)] 'ff/compose-mail)
645 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
651 (when (load "bbdb-vm" t)
653 (defun ff/mail-aliases-from-bbdb ()
654 "Creates automatically mail aliases from the bbdb records. For
655 instance, someone in bbdb named \"Paul Smith\" would generate an alias
656 'pm'. Does not replace existing aliases."
658 (let* ((records (bbdb-records)))
660 (let* ((record (car records))
661 (name (concat (elt record 0) " " (elt record 1)))
662 (email (car (elt record 6)))
663 (alias (downcase (replace-regexp-in-string
664 "\\([a-zA-Z]?\\)[^- ]*[- ]*" "\\1" name))))
665 (if (and (> (length alias) 1)
666 ;; Do not overwrite an existing alias
667 (not (and mail-abbrevs (intern-soft alias mail-abbrevs))))
668 (define-mail-abbrev alias email))
669 (setq records (cdr records))))))
671 (when (>= emacs-major-version 22)
673 (ff/mail-aliases-from-bbdb))
676 (defun ff/pipe-to-tmp () (interactive)
677 (let ((link "/tmp/attach")
678 (dir (format-time-string "/tmp/attach-%Y%m%d-%H%M%S" (current-time))))
680 (when (file-symlink-p link) (delete-file link))
681 (unless (file-exists-p link)
682 (make-symbolic-link dir "/tmp/attach" 1))
683 (vm-pipe-message-to-command (concat "munpack -C " dir))
684 (message "Wrote files to %s" dir)