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 (setq-default vm-summary-show-threads t)
22 ;; (setq vm-preview-lines nil)
24 ;; (setq vm-auto-displayed-mime-content-types '("text"));; "multipart"));; "image/xpm"
26 (setq vm-mime-thumbnail-max-geometry nil)
28 (setq vm-auto-displayed-mime-content-types '(
38 ;; browse-url-mozilla-program "iceweasel"
39 ;; mail-complete-style nil
40 ;; mail-from-style nil
41 ;; vm-coding-system-priorities '(utf-8)
42 ;; vm-highlighted-header-regexp "From:\\|Subject:\\|Cc:\\|To:\\|Bcc:\\|Reply-To:"
43 ;; vm-included-text-attribution-format "\nOn %w, %m %d, at %H, you wrote:\n\n"
44 ;; vm-jump-to-new-messages nil
45 ;; vm-mime-7bit-composition-charset "latin-1"
46 ;; vm-mime-8bit-composition-charset "utf-8"
47 ;; vm-preview-read-messages t
48 ;; vm-summary-format " %*%A %-3.3m %2d %5US %I%UA %s\n"
49 ;; vm-summary-uninteresting-senders-arrow "->"
50 ;; vm-summary-uninteresting-senders-arrow "►"
51 ;; vm-summary-uninteresting-senders-arrow "➔"
52 ;; vm-summary-uninteresting-senders-arrow "➤"
53 bbdb-send-mail-style 'vm
54 bbdb/mail-auto-create-p nil
56 mail-specify-envelope-from t
57 vm-auto-folder-case-fold-search t
58 vm-auto-get-new-mail t
59 vm-circular-folders nil
60 vm-confirm-new-folders t
61 vm-delete-after-archiving t
62 vm-delete-after-saving t
63 vm-forwarding-digest-type "mime"
64 vm-forwarding-subject-format "(forwarded from %F) %s"
65 vm-frame-per-folder nil
66 vm-frame-per-summary nil
67 vm-highlighted-header-regexp "From:\\|Subject:\\|Reply-To:"
68 vm-in-reply-to-format nil
69 vm-included-text-attribution-format "\nOn %w, %m %d, %y (%h), %F wrote:\n\n"
70 vm-included-text-prefix " > "
71 vm-keep-sent-messages nil
72 vm-mime-8bit-composition-charset "iso-8859-1"
73 vm-mime-attachment-save-directory "~/misc/attachments"
74 vm-mime-yank-attachments nil
77 vm-netscape-program browse-url-mozilla-program
79 vm-reply-subject-prefix "Re: "
80 vm-skip-deleted-messages nil
81 vm-skip-read-messages nil
82 vm-startup-message-displayed t
83 vm-startup-with-summary t
85 vm-summary-format " %*%a %-3.3m %2d %5US %I%UA %s\n"
86 vm-summary-thread-indent-level 1
87 vm-summary-uninteresting-senders-arrow ">"
93 ;; (add-to-list 'vm-visible-headers "From " t)
94 (add-to-list 'vm-visible-headers "Reply-To:" t)
95 ;; (add-to-list 'vm-visible-headers "X-Mailer:" t)
96 ;; (add-to-list 'vm-visible-headers "X-from-in-bbdb:" t)
97 ;; (add-to-list 'vm-visible-headers "Return-Path:")
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
100 ;; Mime-related stuff
104 vm-infer-mime-types t
105 vm-mime-use-image-strips nil
106 vm-mime-base64-decoder-program "base64"
107 vm-mime-base64-decoder-switches '("-d")
108 vm-mime-base64-encoder-program "base64"
109 vm-mime-base64-encoder-switches '()
111 vm-mime-internal-content-types '(
119 ;; To force it to be converted to plain text
120 ;; vm-mime-internal-content-type-exceptions '("text/html")
122 vm-mime-external-content-types-alist '(
123 ("application/x-dvi" "xdvi")
124 ("image/postscript" "gv")
125 ("application/pdf" "xpdf")
126 ("application/postscript" "gv")
129 ;; ("text/html" "firefox")
130 ;; ("application/pdf" "epdfview")
135 (require 'vm-rfaddons)
137 ;; The two following lines deal with windows-1252 buggy encoding
139 ;;**;; ;; First, don't display iso-8859-1 as-is in default face
140 ;;**;; (delete "iso-8859-1" vm-mime-default-face-charsets)
141 ;;**;; ;; Then substitute windows-1252 for iso-8859-1
142 ;;**;; (add-to-list 'vm-mime-mule-charset-to-coding-alist '("iso-8859-1" windows-1252))
144 ;; (setq vm-mime-default-face-charsets t)
146 ;; (add-to-list 'vm-mime-default-face-charsets "utf-8")
148 ;; (add-to-list 'vm-mime-default-face-charsets "iso-8859-1")
149 ;; (add-to-list 'vm-mime-default-face-charsets "Windows-1251")
150 ;; (add-hook 'vm-mail-send-hook 'ff/vm-remove-non-7bits-in-headers)
151 (add-hook 'vm-mail-send-hook 'vm-mime-encode-headers)
152 (add-hook 'vm-mail-send-hook 'vm-mail-check-recipients)
153 (add-hook 'vm-reply-hook (lambda () (set-buffer-modified-p nil)))
155 (add-to-list 'vm-mime-attachment-auto-type-alist '(".*" . "application/octet-stream") t)
157 ;; (add-to-list 'vm-mime-type-converter-alist '("text/html" "text/plain" "cat"))
158 ;; (add-to-list 'vm-mime-type-converter-alist '("text/html" "text/plain" "lynx -nolist -force_html -dump -stdin"))
160 ;; (add-to-list 'vm-mime-type-converter-alist
161 ;; '("text/html" "text/plain"
162 ;; "w3m -cols 75 -graph -dump -T text/html"
165 ;; (add-to-list 'vm-mime-type-converter-alist
166 ;; '("text/html" "text/plain"
167 ;; "html2text -style pretty -nobs"
170 ;; (add-to-list 'vm-mime-type-converter-alist
171 ;; '("text/html" "text/plain"
175 (add-to-list 'vm-mime-type-converter-alist
176 '("image" "image/xpm"
177 "/usr/bin/convert -geometry 640x480 - xpm:-"))
179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
181 ;; (defun ff/vm-remove-properties () (interactive)
183 ;; (goto-char (point-min))
184 ;; (re-search-forward (concat "^" mail-header-separator "$"))
185 ;; (set-text-properties (point) (point-max) nil)
189 ;; (add-hook 'vm-mail-send-hook 'ff/vm-remove-properties)
191 ;; (defun ff/vm-mime-save-all-files (&optional delete)
192 ;; "Save all the mail attachments. With delete argument, remove
193 ;; the attachement from mail."
195 ;; (let ((vm-mime-delete-after-saving delete))
196 ;; (while (and (vm-mime-reader-map-save-file)
197 ;; (condition-case nil (vm-move-to-next-button 1)
201 (defun ff/vm-mime-save-file (&optional delete)
202 "Save the current attachement. With delete argument, remove the
203 attachement from mail."
205 (let ((vm-mime-delete-after-saving delete))
206 (vm-mime-reader-map-save-file))
207 (condition-case nil (vm-move-to-next-button 1) (error (message "No more attachment"))))
209 ;; (define-key vm-summary-mode-map [(r)] 'vm-reply-include-text)
210 ;; (define-key vm-summary-mode-map [(R)] 'vm-followup-include-text)
212 (define-key vm-summary-mode-map [(control o)] 'ff/vm-mime-save-file)
214 (define-key vm-summary-mode-map [(control t)]
215 (lambda () (interactive)
216 (vm-toggle-threads-display)
217 (unless vm-summary-show-threads
218 (vm-sort-messages "date"))))
220 (defun ff/vm-select-thread-for-next-command () (interactive)
221 (vm-mark-thread-subtree)
222 (vm-next-command-uses-marks))
224 (define-key vm-summary-mode-map "T" 'ff/vm-select-thread-for-next-command)
226 (defun ff/vm-attach-file-or-dir
228 "Attaches the file or recursively the content of the directory with
229 `vm-mime-attach-file'."
230 (interactive "fFile or directory: ")
233 (goto-char (point-max))
235 (if (file-regular-p dir)
236 (vm-mime-attach-file dir (vm-mime-default-type-from-filename dir))
237 (if (file-directory-p dir)
240 (when (not (string-match "^\\." (car x)))
241 (ff/vm-attach-file-or-dir
243 (unless (string-match "/$" dir) "/")
245 (directory-files-and-attributes dir)
248 (error "Can attach only files and directories")
251 (define-key vm-mail-mode-map [(control c) (control a)] 'ff/vm-attach-file-or-dir)
253 ;; Found no other way to avoid displaying the icones
255 (defun vm-mime-set-image-stamp-for-type (e type))
257 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
260 (defun vm-summary-function-A (message)
261 (let* ((from (vm-su-from message)))
262 (if (string-match vm-summary-uninteresting-senders from)
263 (concat vm-summary-uninteresting-senders-arrow " " (ff/explicit-name (vm-su-to message)))
264 (ff/explicit-name from))))
266 (defun vm-summary-function-S (&optional message)
267 (let ((s (string-to-int (vm-su-byte-count message))))
269 (propertize (concat (int-to-string (/ s 1024)) "k")
274 (defun ff/vm-delete-and-go-down () (interactive)
276 (vm-delete-message 1)
277 (condition-case nil (vm-next-message-no-skip 1) (error nil)))
279 (defun ff/vm-expunge-folder ()
280 (unless vm-folder-read-only (vm-expunge-folder)))
282 (add-hook 'vm-quit-hook 'ff/vm-expunge-folder)
283 (add-hook 'vm-quit-hook 'bbdb-save-db)
284 (add-hook 'vm-retrieved-spooled-mail-hook 'display-time-update)
286 (ff/configure-faces '((ff/summary-highlight-face :background "yellow"
290 (setq vm-summary-highlight-face 'ff/summary-highlight-face)
292 (define-key vm-summary-mode-map [(K)] 'ff/vm-delete-and-go-down)
294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
295 ;; Activate the required modes and authorize the commenting
297 (defun ff/prepare-mail-mode ()
298 (bbdb-define-all-aliases)
303 ;; (setq fill-paragraph-function 'mail-mode-fill-paragraph)
305 ;; Since I set the comment prefix, I have to tell the filling
306 ;; functions not to use it
308 ;; ******************* removed Aug 23
309 ;; (setq fill-paragraph-handle-comment nil)
310 ;; ;; (when message-yank-prefix
311 (set (make-local-variable 'comment-start) vm-included-text-prefix)
312 ;; (set (make-local-variable 'comment-start-skip)
313 ;; (concat "^\\(" (regexp-quote vm-included-text-prefix) "\\)"))
317 (add-hook 'mail-mode-hook 'ff/prepare-mail-mode)
318 ;; (add-hook 'mail-mode-hook 'orgtbl-mode)
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
321 ;; To have a slightly darker background for headers
324 ;; '((ff/mail-header-face :background "#c8c8ff"))
325 '((ff/mail-header-face :foreground "blue4"))
328 (defun ff/colorize-headers () (interactive)
329 (let ((inhibit-read-only t))
331 (goto-char (point-min))
332 (while (vm-match-header)
333 (goto-char (vm-matched-header-end)))
335 ;; (vm-matched-header-contents-start)
336 ;; (vm-matched-header-contents-end)
339 '(face ff/mail-header-face)
343 (defadvice vm-highlight-headers (after ff/colorize-headers nil activate)
344 (ff/colorize-headers))
346 (defun ff/highlight-important-words ()
347 (let ((inhibit-read-only t))
349 (goto-char (point-min))
350 (while (re-search-forward "Fleuret" nil t)
351 (message "%d-%d" (match-beginning 0) (match-end 0))
352 ;; (add-text-properties (match-beginning 0) (match-end 0)
353 ;; '(face (:background "red"))
358 ;; (add-hook 'vm-select-message-hook 'ff/highlight-important-words)
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361 ;; I want to have a file associated to every mail I am writing
363 (defcustom ff/vm-mail-draft-directory "~/"
364 "Where to save mail drafts with VM")
366 (defun ff/associate-file-to-vm-mail-buffer ()
367 "Associate the current buffer to a file whose name is built from the current time."
368 (unless (buffer-file-name)
369 (set-visited-file-name (format
371 ff/vm-mail-draft-directory
373 "%04Y%02m%02d-%02H%02M%02S"
375 (set-buffer-modified-p nil)))
377 (add-hook 'mail-setup-hook 'ff/associate-file-to-vm-mail-buffer)
379 (defun ff/mail-header-field (field) (interactive)
380 "Grab the value of a certain field from the mail header."
381 (let ((s "no-subject"))
383 (goto-char (point-min))
384 (let ((l (re-search-forward (concat "^" mail-header-separator "$") nil t)))
386 (goto-char (point-min))
387 (when (re-search-forward (concat "^" field ": ") l t nil)
388 (setq s (buffer-substring-no-properties (point) (point-at-eol))))
394 (defun ff/dissociate-file-from-vm-mail-buffer ()
395 "Save the file under a new name and set the associated file to nil."
396 (let ((bn (buffer-file-name)))
398 (set-visited-file-name
399 (concat (file-name-directory bn)
401 (file-name-nondirectory bn)
403 (replace-regexp-in-string "[^a-zA-Z0-9]+" "_"
404 (ff/mail-header-field "Subject"))
407 (set-visited-file-name nil))
411 (defun ff/find-file-in-vm-mail-mode (filename) (interactive)
412 ;; No easy way to activate vm-mail-mode, so we create such a
413 ;; buffer, erase its content and insert the file
415 (when (file-exists-p filename)
417 (insert-file filename))
418 (set-visited-file-name filename)
419 (set-buffer-modified-p nil)
420 ;; (run-hooks find-file-hooks)
421 (when (functionp 'alarm-vc-check) (alarm-vc-check))
422 ;; Move the cursor at a convenient location
423 (when (re-search-forward (concat "^" mail-header-separator "$") nil t)
424 (if (re-search-forward "^-- $" nil t)
430 ;; All this mess to activate the vm-mail-mode when loading a file
431 ;; looking like a mail draft. Did I miss something ?
433 (defadvice find-file (around ff/find-file-or-mail
434 (filename &optional wildcards)
437 (interactive "FFind file: \np")
439 (if (string-match "^\\(mail\\|sent\\)-[^/]+$"
440 (file-name-nondirectory filename))
442 (if (find-buffer-visiting filename)
443 (switch-to-buffer (find-buffer-visiting filename))
444 (ff/find-file-in-vm-mail-mode filename))
448 (setq ff/vm-mail-draft-directory "~/private/drafts")
450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
451 ;; Check there are no missing attachment (the idea comes from
452 ;; http://home.cc.gatech.edu/eaganj/MailApp) and no leading "From"
453 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
455 (defcustom ff/check-vm-attachement-regexp "attach"
456 "*A mail whose body matches this regular expression should contain
459 (defun ff/check-vm-attachment ()
460 (when (save-excursion
461 (goto-char (point-min))
462 (and (re-search-forward "\\[ATTACHMENT" nil t)
463 (not (get-text-property (point) 'vm-mime-object))))
464 (error "Buggy attachment"))
467 (save-excursion (goto-char (point-min))
468 (re-search-forward ff/check-vm-attachement-regexp nil t))
469 (not (save-excursion (goto-char (point-min))
470 (re-search-forward "\\[ATTACHMENT" nil t)))
471 (not (y-or-n-p "An attachment seems to be missing, send message ? ")))
472 (error "You refer to an unexisting attachment."))
476 ;; You can not have a line starting with "From:" in a pure text
477 ;; mail. The smtp server would add a leading character to prevent it.
479 (defun ff/check-no-leading-from ()
480 (and (let ((case-fold-search nil))
482 (goto-char (point-min))
483 (re-search-forward (concat "^" mail-header-separator "$"))
484 (re-search-forward "^From " nil t)))
485 (not (y-or-n-p "There is a leading ``From '', send message ? "))
486 (error "There is a leading ``From ''.")))
488 ;; An attempt at limiting excess wording in sent mails
490 (defface ff/strong-words
491 '((t (:background "red")))
492 "The face to highlight upper caps, exclamation marks and such.")
494 (defun ff/max-in-a-row (overlay regexp max)
495 (let ((case-fold-search nil))
497 (goto-char (point-min))
498 (re-search-forward (concat "^" mail-header-separator "$"))
499 (when (and (re-search-forward regexp nil t nil)
500 (>= (- (match-end 0) (match-beginning 0)) max))
501 (move-overlay overlay (match-beginning 0) (match-end 0))
504 (defun ff/check-no-excess-wording () (interactive)
505 (let ((overlay (make-overlay 0 0)))
506 (overlay-put overlay 'face 'media/current-tune-face)
508 (or (ff/max-in-a-row overlay "[A-Z\?\!][A-Z\?\! ]+[A-Z\?\!]" 6)
509 (ff/max-in-a-row overlay "[\?\!]+" 2)
511 (not (y-or-n-p "That does not look good. Send message ? ")))))
512 (delete-overlay overlay)
513 (when err (error "Good idea. Chill out a bit.")))
516 (defun ff/check-badly-encoded-address () (interactive)
517 (let (bodysep bad-adr)
519 (goto-char (point-min))
520 (search-forward mail-header-separator)
521 (setq bodysep (vm-marker (match-beginning 0)))
522 (goto-char (point-min))
523 (setq bad-adr (re-search-forward "[^<a-zA-Z_0-9\-\. \n\t]+[^ \n]*@" nil t))
524 (when (and bad-adr (< bad-adr bodysep))
525 (error "There is an invalid address in the header (%s)"
529 (add-hook 'vm-mail-send-hook 'ff/check-vm-attachment)
530 (add-hook 'vm-mail-send-hook 'ff/check-no-leading-from)
531 (add-hook 'vm-mail-send-hook 'ff/check-no-excess-wording)
532 (add-hook 'vm-mail-send-hook 'flyspell-mode-off)
533 ;; Append so that it happens after the mime encoding
534 ;; (add-hook 'vm-mail-send-hook 'ff/check-badly-encoded-address t)
536 ;; Append this hook so that it runs after all other checks
537 (add-hook 'vm-mail-send-hook 'ff/dissociate-file-from-vm-mail-buffer t)
539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
540 ;; If we can, encrypt!
542 (add-hook 'vm-mode-hook 'mc-install-read-mode)
543 (add-hook 'vm-summary-mode-hook 'mc-install-read-mode)
544 (add-hook 'vm-virtual-mode-hook 'mc-install-read-mode)
545 (add-hook 'vm-mail-mode-hook 'mc-install-write-mode)
546 (add-hook 'vm-presentation-mode-hook 'mc-install-read-mode)
548 ;; (defun ff/encrypt-mail-if-possible () (interactive)
549 ;; (condition-case nil (mc-encrypt-message)
552 ;; (add-hook 'vm-mail-send-hook 'ff/encrypt-mail-if-possible t)
554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
557 ;; Move through important points in the mail ("To:" field, "Subject:"
558 ;; field and the end of the body)
560 (defun ff/goto-next-mail-field () (interactive)
561 (let ((field (save-excursion
564 (concat "\\(^[a-zA-Z\-]*: \\|^" mail-header-separator "$\\)") nil t)
567 (cond ((string= field "To: ")
569 (re-search-forward "Subject: ")
572 ((string= field "Subject: ")
573 (re-search-forward (concat "^" mail-header-separator "$"))
574 (if (re-search-forward "^-- $" nil t)
579 (t (beginning-of-buffer)
580 (re-search-forward "^To: ")
582 (re-search-forward "^[a-zA-Z\-]*: ")
586 ;; (define-key vm-mail-mode-map [(control tab)] 'ff/goto-next-mail-field)
587 (define-key vm-mail-mode-map [(iso-lefttab)] 'ff/goto-next-mail-field)
588 ;; (define-key vm-mail-mode-map [(shift iso-lefttab)] 'mail-mode-smart-tab)
589 (define-key vm-mail-mode-map [(shift iso-lefttab)] 'bbdb-complete-name)
591 ;; The definition of "\t" is forced through a hook defined in
592 ;; vm-init.el, so I add mine. This is ugly.
594 (add-hook 'mail-setup-hook
595 '(lambda () (local-set-key "\t" 'ff/goto-next-mail-field))
598 (substitute-key-definition 'next-line 'mail-abbrev-next-line vm-mail-mode-map global-map)
600 (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer vm-mail-mode-map global-map)
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 ;; I rarely edit two mails at the same time, and it makes sense to
604 ;; come back to the one currently being edited with the same function
606 (defun ff/first-buffer-in-mode (l m)
608 (if (eq (save-excursion
609 (set-buffer (car l)) major-mode) m)
611 (ff/first-buffer-in-mode (cdr l) m))))
613 (defun ff/compose-mail (&optional force-new)
614 "Cycles through an existing buffers with major mode `mail-mode',
615 or invoke `vm-compose-mail' if none can be found or if FORCE-NEW
618 (when (eq major-mode 'mail-mode) (bury-buffer))
619 (let ((buf (and (not force-new)
620 (ff/first-buffer-in-mode (buffer-list) 'mail-mode))))
621 (if buf (switch-to-buffer buf)
624 (define-key global-map [(control x) (m)] 'ff/compose-mail)
626 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
632 (when (load "bbdb-vm" t)
634 (defun ff/mail-aliases-from-bbdb ()
635 "Creates automatically mail aliases from the bbdb records. For
636 instance, someone in bbdb named \"Paul Smith\" would generate an alias
637 'pm'. Does not replace existing aliases."
639 (let* ((records (bbdb-records)))
641 (let* ((record (car records))
642 (name (concat (elt record 0) " " (elt record 1)))
643 (email (car (elt record 6)))
644 (alias (downcase (replace-regexp-in-string
645 "\\([a-zA-Z]?\\)[^- ]*[- ]*" "\\1" name))))
646 (if (and (> (length alias) 1)
647 ;; Do not overwrite an existing alias
648 (not (and mail-abbrevs (intern-soft alias mail-abbrevs))))
649 (define-mail-abbrev alias email))
650 (setq records (cdr records))))))
652 (when (>= emacs-major-version 22)
654 (ff/mail-aliases-from-bbdb))
657 (defun ff/pipe-to-tmp () (interactive)
658 (let ((link "/tmp/attach")
659 (dir (format-time-string "/tmp/attach-%Y%m%d-%H%M%S" (current-time))))
661 (when (file-symlink-p link) (delete-file link))
662 (unless (file-exists-p link)
663 (make-symbolic-link dir "/tmp/attach" 1))
664 (vm-pipe-message-to-command (concat "munpack -C " dir))
665 (message "Wrote files to %s" dir)