当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 4 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 写了一个脚本,在EMACS里写信,再直接调用MUTT发信
帖子发表于 : 2010-08-22 14:52 

注册: 2008-12-26 17:33
帖子: 38
送出感谢: 0 次
接收感谢: 0 次
不知道有没有人已经实现了这个功能?有的话请大侠给个链接。

脚本很烂,N多BUG,但勉强可用。

用法: 用C-c m 写信,
用C-c C-c 发信,
地址栏中[To: BCC: CC:]用<TAB>,将用一个buffer读取.mutt/alias文件,将光标移到某行,用回车选取该行地址,

函数mutt-add-attachment 添加附件[绑定到H-a],函数mutt-add-BCC添加暗送[绑定到H-d],
mutt-add-CC添加抄送[绑定到H-b],
Mode 函数还有以下内容:
(define-key map (kbd "H-t") 'mutt-goto-to-address) 将光标移到地址栏
(define-key map (kbd "H-a") 'mutt-add-attachment) 将光标移到
(define-key map (kbd "H-s") 'mutt-goto-subject)将光标移到主题栏
(define-key map (kbd "H-b") 'mutt-goto-body)将光标移到邮件内容
(define-key map (kbd "H-c") 'mutt-add-CC)
(define-key map (kbd "H-d") 'mutt-add-BCC)
(define-key map (kbd "<tab>") 'mutt-indent)
(define-key map (kbd "s-c") 'mutt-send-mail)
(define-key map (kbd "C-c C-c") 'mutt-send-mail)
(define-key map (kbd "H-i") 'mutt-insert-signature)添加签名





代码:
;;; zfmmuttsendmail.el
;; Created at 2010/08/17, and finished at 2010/08/20,14:35:52 Friday
;; Send mail by mutt without getting out of emacs.


;; TODO:
;;      (1) auto insert address by consulting the addressbook.
;;      (2) there are still some bug in it:
;;              when inserting the address the point sometimes is wrong.

(global-set-key (kbd "A-m") 'mutt-write-letter)
(global-set-key (kbd "C-c m") 'mutt-write-letter)

(defvar zfm-default-to-address "ahnuzfm@163.com"
  "This address is the default mail address.")

(defvar zfm-letter-body-start "------------ BODY START -----------------------")
(defvar zfm-letter-body-end   "------------ BODY END -------------------------")


(defvar zfmmail-mode-font-lock-keywords    ;keyword for buffer display
  '(
    ("^To: .*" .  font-lock-type-face)
    ("^CC: .*" .  font-lock-type-face)
    ("^BCC: .*" .  font-lock-type-face)
    ("^Subject: .*" .  font-lock-function-name-face)
    ("^Attachment: .*" .  font-lock-function-name-face)
    ("^---+.*" . font-lock-comment-face)
    )
  "Expressions to highlight in `zfmmail-mode'.")
 
(defun mutt-to-address ()
  (save-excursion
    (goto-char (point-min))
    (buffer-substring-no-properties
     (progn (re-search-forward "^To: " nil t 1) (point))
     (progn (end-of-line) (point)))))
 
(defun mutt-attachment ()
  (save-excursion
    (goto-char (point-min))
    (condition-case nil
      (format "-a %s"
         (buffer-substring-no-properties
          (progn (re-search-forward "^Attachment: " nil nil 1) (point))
          (progn (end-of-line) (point))))
      (error ""))))

(defun mutt-add-attachment ()
  (interactive)
  (goto-char (point-min))
  (condition-case nil
      (re-search-forward "^Attachment: " nil nil 1)
    (error
     (progn
       (re-search-forward "^Subject: " nil t 1)
       (forward-line)
       (insert "Attachment: \n")
       (forward-line -1)
       (end-of-line)))))

(defun mutt-BCC ()
  (save-excursion
    (goto-char (point-min))
    (condition-case nil
   (format "-b %s"
      (buffer-substring-no-properties
       (progn (re-search-forward "^BCC: " nil nil 1) (point))
       (progn (end-of-line) (point))))
      (error ""))))

(defun mutt-add-BCC ()
  (interactive)
  (goto-char (point-min))
  (condition-case nil
      (re-search-forward "^BCC: " nil nil 1)
    (error
     (progn
       (re-search-forward "^To: " nil t 1)
       (forward-line)
       (insert "BCC: \n")
       (forward-line -1)
       (end-of-line)))))

(defun mutt-add-CC ()
  (interactive)
  (goto-char (point-min))
  (condition-case nil
      (re-search-forward "^CC: " nil nil 1)
    (error
     (progn
       (re-search-forward "^To: " nil t 1)
       (forward-line)
       (insert "CC: \n")
       (forward-line -1)
       (end-of-line)))))

(defun mutt-CC ()
  (save-excursion
    (goto-char (point-min))
    (condition-case nil
   (format "-c %s"
      (buffer-substring-no-properties
       (progn   (re-search-forward "^CC: " nil nil 1) (point))
       (progn (end-of-line) (point))))
      (error ""))))

(defun mutt-subject ()
  (save-excursion
    (goto-char (point-min))
    (buffer-substring-no-properties
     (progn (re-search-forward "^Subject: " nil t 1) (point))
     (progn (end-of-line) (point)))))
 
(defun mutt-letter-body ()
  (save-excursion
    (goto-char (point-min))
    (buffer-substring-no-properties
     (progn (search-forward zfm-letter-body-start nil t 1)
       (forward-line 1) (beginning-of-line) (point))
     (progn (search-forward zfm-letter-body-end nil t 1)
       (forward-line 0) (beginning-of-line) (point)))))
 
(defun mutt-goto-to-address ()
  "Go to the to address of the letter"
  (interactive)
    (goto-char (point-min))
    (re-search-forward "^To: " nil t 1))
 
(defun mutt-goto-attachment ()
  "Go to the to attachment of the letter"
  (interactive)
    (goto-char (point-min))
    (re-search-forward "^Attachment: " nil t 1))

(defun mutt-goto-subject ()
  "Go to the to subject of the letter"
  (interactive)
    (goto-char (point-min))
    (re-search-forward "^Subject: " nil t 1))

(defun mutt-goto-body ()
  "Go to the to body of the letter"
  (interactive)
    (goto-char (point-min))
    (search-forward zfm-letter-body-start nil t 1)
    (forward-line))
 
(defun mutt-insert-signature ()
  "Insert the signature file ~/.signature"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (search-forward zfm-letter-body-end nil t 1)
    (beginning-of-line)
    (insert "\n--")
    (insert-file "~/.signature")
    (insert "\n")))

(defun mutt-send-mail ()
  "Invoking mutt to send the mail in current buffer."
  (interactive)
  (condition-case nil
      (progn
   (shell-command (format "echo \"%s\" | mutt -s \"%s\" %s %s %s -- %s"
              (mutt-letter-body)
              (mutt-subject)
              (mutt-attachment)
              (mutt-BCC)
              (mutt-CC)
              (mutt-to-address)))
   (message (format "Message sent to %s successfully."
          (mutt-to-address))))
    (error (message "Fail to sending message."))))

(defun mutt-write-letter ()
  (interactive)
  (let ((buffer (get-buffer-create "*ZfmMail*")))
    (with-current-buffer buffer
      (insert (format "To: %s\n" zfm-default-to-address))
      (insert (format "Subject: \n"))
      ;(insert "Attachment: ~/mutt.sh")
      (insert (format "%s\n" zfm-letter-body-start))
      ;(insert (format " (mutt-send-mail) \n"))
      (insert (format "\n%s\n" zfm-letter-body-end))
      (insert "All the lines from here are ignored.\n")
      (insert "The line containning CC and BCC without actual address should be erased,\n")
      (insert "since this code is not fully developed.\n")
      (goto-char (point-min))
      (search-forward "Subject: ")
      ;(forward-line)
      (unless (eq major-mode 'zfmmail-mode) (zfmmail-mode))
      (setq mutt-compose-buffer-name (buffer-file-name))
      (write-file (format-time-string "/tmp/mutt-mail-%Y%m%d-%H%M%S.zfmmail"))
      ;(write-file "/tmp/mutt-mail.zfmmail")
      )
    buffer
    (switch-to-buffer buffer)))

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun mutt-read-address ()
  (interactive)
  (beginning-of-line)
  (search-forward "@" nil t)
  (setq mutt-current-address
   (buffer-substring-no-properties
    (progn (search-forward " " nil t -1) (forward-char)  (point))
    (progn (search-forward " " nil t 1) (forward-char -1) (point))))
  (message (format "Current address: %s." mutt-current-address))
  (with-current-buffer (other-buffer)
    (insert mutt-current-address))
  (kill-buffer "*mutt-adress*")
;  (switch-to-buffer mutt-compose-buffer-name)
)

(defvar mutt-adress-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "<return>") 'mutt-read-address)
    map))

(define-derived-mode mutt-adress nil "mutt-adress"
"Major mode to edit mail and send it by mutt without getting out of emacs.
\\{zfmmail-mode-map}
Turning on Text mode runs the normal hook `zfmmail-mode-hook'."
  ;(setq font-lock-defaults '(zfmmail-mode-font-lock-keywords))
  (setq buffer-read-only nil)
  (use-local-map mutt-adress-mode-map)
  (set (make-local-variable 'outline-regexp) "^-->.*\n-->"))
 
(defun mutt-address-buffer ()
  (interactive)
  (let ((buffer (get-buffer-create "*mutt-adress*")))
    (with-current-buffer buffer
      (insert-file "~/.mutt/alias")
      (goto-char (point-min))
      (unless (eq major-mode 'mutt-adress) (mutt-adress)))
    buffer
    (switch-to-buffer buffer)))

(defun mutt-indent ()
  "If in the to address line, redefine TAB key to read .mutt/alias file for
the address, otherwise do the normal TAB function."
  (interactive)
  (setq m1 (point-marker))
  (save-excursion
    (let ((string
      (buffer-substring-no-properties
       (progn (beginning-of-line) (point))
       (progn (forward-char 4) (point)))))
      (if  (or (string= string "To: ") (string= string "CC: "))
     (progn (beginning-of-line)
       (forward-char 4)
       (kill-line)
       (mutt-address-buffer))
   (progn (goto-char (marker-position m1))
          (indent-for-tab-command)))
      (if  (string= string "BCC:")
     (progn (beginning-of-line)
       (forward-char 5)
       (kill-line)
       (mutt-address-buffer))
   (progn (goto-char (marker-position m1))
          (indent-for-tab-command)))))
  (set-marker m1 nil))

(defvar zfmmail-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "H-t") 'mutt-goto-to-address)
    (define-key map (kbd "H-a") 'mutt-add-attachment)
    (define-key map (kbd "H-s") 'mutt-goto-subject)
    (define-key map (kbd "H-b") 'mutt-goto-body)
    (define-key map (kbd "H-c") 'mutt-add-CC)
    (define-key map (kbd "H-d") 'mutt-add-BCC)
    (define-key map (kbd "<tab>") 'mutt-indent)
    (define-key map (kbd "s-c") 'mutt-send-mail)
    (define-key map (kbd "C-c C-c") 'mutt-send-mail)
    (define-key map (kbd "H-i") 'mutt-insert-signature)
    map)
  "Keymap for `zfmmail-mode'.")

(define-derived-mode zfmmail-mode nil "zfmmail"
"Major mode to edit mail and send it by mutt without getting out of emacs.
\\{zfmmail-mode-map}
Turning on Text mode runs the normal hook `zfmmail-mode-hook'."
  (setq font-lock-defaults '(zfmmail-mode-font-lock-keywords))
  (setq buffer-read-only nil)
  (use-local-map zfmmail-mode-map)
  (set (make-local-variable 'outline-regexp) "^-->.*\n-->"))



最后由 ahnuzfm 编辑于 2010-08-22 15:11,总共编辑了 1 次

页首
 用户资料  
 
2 楼 
 文章标题 : Re: 写了一个脚本,在EMACS里写信,再直接调用MUTT发信
帖子发表于 : 2010-08-22 15:01 

注册: 2008-12-26 17:33
帖子: 38
送出感谢: 0 次
接收感谢: 0 次
附一个截图:图片


附件:
文件注释: 附一个截图
a.jpg
a.jpg [ 144.54 KiB | 被浏览 852 次 ]

页首
 用户资料  
 
3 楼 
 文章标题 : Re: 写了一个脚本,在EMACS里写信,再直接调用MUTT发信
帖子发表于 : 2010-08-22 15:13 
头像

注册: 2009-05-31 17:40
帖子: 737
地址: NO
送出感谢: 2
接收感谢: 1
用gnus发不是很好么?


_________________
No.


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 写了一个脚本,在EMACS里写信,再直接调用MUTT发信
帖子发表于 : 2010-08-25 14:12 

注册: 2008-12-26 17:33
帖子: 38
送出感谢: 0 次
接收感谢: 0 次
试了一下用_GNUS果然更好,只是打开时有点慢。


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 4 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译