Add KDE-emacs/GNUS mail integration tools
[emacsstuff.git] / mail / emacs-mail.el
1 ;;; cc-ide.el --- C++ IDE
2 ;;
3 ;; $Id$
4 ;;
5 ;; Copyright (C) 2000 Stefan Bund
6
7 ;; cc-ide.el is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 2, or (at your
10 ;; option) any later version.
11
12 ;; cc-ide.el is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16
17 ;;; Commentary:
18
19 ;;; Change-Log:
20
21 ;; $Log$
22 ;;
23
24 ;;; Variables:
25
26 ;;; Code:
27
28 (defun mail-add-header (header value &optional separator)
29   (when (and value (> (length value) 0))
30     (mail-position-on-field header)
31     (if (save-excursion
32           (skip-chars-backward " \t\n\r")
33           (not (eq (preceding-char) ?:)))
34         (insert separator))
35     (insert value)))
36
37 (defun write-mail (&optional to subject cc bcc body attachment)
38   (interactive)
39   (loop for b in (buffer-list)
40         if (eq major-mode 'message-mode)
41             return (pop-to-buffer b)
42         finally (progn
43                   (if (eq major-mode 'gnus-summary-mode)
44                       (gnus-summary-mail-other-window)
45                     (gnus-group-mail))
46                   (goto-char (point-max))
47                   (if (re-search-backward "^-- $" nil)
48                       (forward-line -1))))
49   (save-excursion
50     (mail-add-header "To" to ",\n  ")
51     (mail-add-header "Subject" subject "; ")
52     (mail-add-header "CC" cc ", ")
53     (mail-add-header "BCC" bcc ", "))
54   (if body (insert body))
55 ;;       (when (file-readable-p "~/.signature")
56 ;;         (insert "\n-- \n")
57 ;;         (insert-file "~/.signature")
58 ;;         (goto-char (point-max))
59 ;;         (if (not (bolp))
60 ;;             (insert "\n")))
61   (when (and attachment (> (length attachment) 0))
62     (if (and (> (length attachment) 5)
63              (string= (substring attachment 0 5) "file:"))
64         (setq attachment (substring attachment 5)))
65     (when (file-readable-p attachment)
66       (save-excursion
67         (goto-char (point-max))
68         (insert "\n")
69         (mime-edit-insert-file attachment))))
70   (font-lock-fontify-buffer))
71
72 (provide 'emacs-mail)