忘记在邮件里添加附件,是件很尴尬的事情,这不,昨天就又干了一回。再也不能这样活!于是乎对message-mode做了一点扩展,在发送邮件之前扫描邮件正文,如发现有”attached”或者”attachment”字样,却没有发现附件的话,就提醒一下。代码如下:
(defvar wl-message-attachment-word-regex "attached\|attachment"
"List of words indicates the existence of attachment.")
(defun wl-message-attachment-mentioned-p ()
"If attachment is mentioned is message body"
(save-excursion
(message-goto-body)
(let ((end (or (and message-reply-headers (re-search-forward (concat (mail-header-from message-reply-headers) " writes:") nil t))
(point-max))))
(message-goto-body)
(re-search-forward wl-message-attachment-word-regex end t))))
(defun wl-message-attachment-found-p ()
"If there is really attachment"
(save-excursion
(message-goto-body)
(re-search-forward "<#part .+ filename=.+ disposition=attachment>" nil t)))
(defadvice message-fix-before-sending (after attachment-reminder
())
(message-check 'attachment
(when (and (wl-message-attachment-mentioned-p)
(not (wl-message-attachment-found-p)))
(unless (y-or-n-p "Attachment not found; continue sending? ")
(error "Attachment not found")))))
(ad-activate 'message-fix-before-sending)





