2014-09-24 16:06:26 +02:00
|
|
|
|
;; -*-mode: emacs-lisp; tab-width: 8; indent-tabs-mode: t -*-
|
2012-04-11 21:31:52 +02:00
|
|
|
|
;; mu4e-compose.el -- part of mu4e, the mu mail user agent for emacs
|
2011-09-18 13:39:36 +02:00
|
|
|
|
;;
|
2012-03-31 13:22:06 +02:00
|
|
|
|
;; Copyright (C) 2011-2012 Dirk-Jan C. Binnema
|
2011-09-18 13:39:36 +02:00
|
|
|
|
|
|
|
|
|
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
|
|
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
;;
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; In this file, various functions to compose/send messages, piggybacking on
|
2011-10-10 07:38:14 +02:00
|
|
|
|
;; gnus' message mode
|
2011-09-18 13:39:36 +02:00
|
|
|
|
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
|
|
|
|
;; Magic / Rupe Goldberg
|
|
|
|
|
|
|
|
|
|
;; 1) When we reply/forward a message, we get it from the backend, ie:
|
|
|
|
|
;; we send to the backend (mu4e-compose):
|
|
|
|
|
;; compose type:reply docid:30935
|
|
|
|
|
;; backend responds with:
|
|
|
|
|
;; (:compose reply :original ( .... <original message> ))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 2) When we compose a message, message and headers are separated by
|
|
|
|
|
;; `mail-header-separator', ie. '--text follows this line--. We use
|
|
|
|
|
;; before-save-hook and after-save-hook to remove/re-add this special line, so
|
|
|
|
|
;; it stays in the buffer, but never hits the disk.
|
|
|
|
|
;; see:
|
|
|
|
|
;; mu4e~compose-insert-mail-header-separator
|
|
|
|
|
;; mu4e~compose-remove-mail-header-separator
|
|
|
|
|
;;
|
|
|
|
|
;; (maybe we can get away with remove it only just before sending? what does
|
|
|
|
|
;; gnus do?)
|
|
|
|
|
|
|
|
|
|
;; 3) When sending a message, we want to do a few things:
|
|
|
|
|
;; a) move the message from drafts to the sent folder (maybe; depends on
|
|
|
|
|
;; `mu4e-sent-messages-behavior')
|
|
|
|
|
;; b) if it's a reply, mark the replied-to message as "R", i.e. replied
|
|
|
|
|
;; if it's a forward, mark the forwarded message as "P", i.e. passed (forwarded)
|
|
|
|
|
;; c) kill all buffers looking at the sent message
|
|
|
|
|
|
|
|
|
|
;; a) is dealt with by message-mode, but we need to tell it where to move the
|
|
|
|
|
;; sent message. We do this by adding an Fcc: header with the target folder,
|
2013-02-21 19:47:03 +01:00
|
|
|
|
;; see `mu4e~compose-setup-fcc-maybe'. Since message-mode does not natively
|
2012-10-29 11:27:32 +01:00
|
|
|
|
;; understand maildirs, we also need to tell it what to do, so we also set
|
|
|
|
|
;; `message-fcc-handler-function' there. Finally, we add the the message in
|
|
|
|
|
;; the sent-folder to the database.
|
|
|
|
|
;;
|
|
|
|
|
;; b) this is handled in `mu4e~compose-set-parent-flag'
|
|
|
|
|
;;
|
|
|
|
|
;; c) this is handled in our handler for the `sent'-message from the backend
|
|
|
|
|
;; (`mu4e-sent-handler')
|
|
|
|
|
;;
|
|
|
|
|
|
2011-09-18 13:39:36 +02:00
|
|
|
|
;;; Code:
|
2012-06-10 15:14:21 +02:00
|
|
|
|
|
|
|
|
|
(eval-when-compile (byte-compile-disable-warning 'cl-functions))
|
2012-04-09 15:34:52 +02:00
|
|
|
|
(require 'cl)
|
2012-06-10 15:14:21 +02:00
|
|
|
|
|
2011-09-18 13:39:36 +02:00
|
|
|
|
(require 'message)
|
|
|
|
|
(require 'mail-parse)
|
2011-12-29 00:25:52 +01:00
|
|
|
|
(require 'smtpmail)
|
2012-06-19 13:12:54 +02:00
|
|
|
|
(require 'rfc2368)
|
2011-09-18 13:39:36 +02:00
|
|
|
|
|
2012-04-11 21:31:52 +02:00
|
|
|
|
(require 'mu4e-utils)
|
|
|
|
|
(require 'mu4e-vars)
|
|
|
|
|
(require 'mu4e-proc)
|
2012-05-01 21:45:54 +02:00
|
|
|
|
(require 'mu4e-actions)
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(require 'mu4e-message)
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(require 'mu4e-draft)
|
2011-09-18 13:39:36 +02:00
|
|
|
|
|
2012-04-24 17:13:12 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; Composing / Sending messages
|
|
|
|
|
(defgroup mu4e-compose nil
|
|
|
|
|
"Customizations for composing/sending messages."
|
|
|
|
|
:group 'mu4e)
|
|
|
|
|
|
|
|
|
|
(defcustom mu4e-sent-messages-behavior 'sent
|
2012-11-05 17:16:46 +01:00
|
|
|
|
"Determines what mu4e does with sent messages.
|
2012-10-01 20:18:06 +02:00
|
|
|
|
|
2012-11-05 17:16:46 +01:00
|
|
|
|
This is one of the symbols:
|
|
|
|
|
* `sent' move the sent message to the Sent-folder (`mu4e-sent-folder')
|
|
|
|
|
* `trash' move the sent message to the Trash-folder (`mu4e-trash-folder')
|
|
|
|
|
* `delete' delete the sent message.
|
2012-10-01 20:18:06 +02:00
|
|
|
|
|
2012-12-12 20:03:36 +01:00
|
|
|
|
Note, when using GMail/IMAP, you should set this to either
|
|
|
|
|
`trash' or `delete', since GMail already takes care of keeping
|
2013-04-21 11:40:57 +02:00
|
|
|
|
copies in the sent folder.
|
|
|
|
|
|
|
|
|
|
Alternatively, `mu4e-sent-messages-behavior' can be a function
|
|
|
|
|
which takes no arguments, and which should return on of the mentioned symbols,
|
|
|
|
|
for example:
|
|
|
|
|
|
|
|
|
|
(setq mu4e-sent-messages-behavior (lambda ()
|
|
|
|
|
(if (string= (message-sendmail-envelope-from) \"foo@example.com\")
|
|
|
|
|
'delete 'sent)))
|
|
|
|
|
|
|
|
|
|
The various `message-' functions from `message-mode' are available
|
2014-09-23 01:40:35 +02:00
|
|
|
|
for querying the message information."
|
2013-04-21 11:40:57 +02:00
|
|
|
|
:type '(choice (const :tag "move message to mu4e-sent-folder" sent)
|
2012-12-12 20:03:36 +01:00
|
|
|
|
(const :tag "move message to mu4e-trash-folder" trash)
|
|
|
|
|
(const :tag "delete message" delete))
|
2012-04-24 17:13:12 +02:00
|
|
|
|
:safe 'symbolp
|
|
|
|
|
:group 'mu4e-compose)
|
2012-05-11 20:08:26 +02:00
|
|
|
|
|
2013-10-20 14:41:47 +02:00
|
|
|
|
(defcustom mu4e-compose-pre-hook nil
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Hook run just *before* message composition starts.
|
2013-09-28 19:36:57 +02:00
|
|
|
|
If the compose-type is either 'reply' or 'forward', the variable
|
2012-08-29 17:00:23 +02:00
|
|
|
|
`mu4e-compose-parent-message' points to the message replied to /
|
2013-09-28 19:36:57 +02:00
|
|
|
|
being forwarded / edited.
|
|
|
|
|
|
|
|
|
|
Note that there is no draft message yet when this hook runs, it
|
|
|
|
|
is meant for influencing the how mu4e constructs the draft
|
|
|
|
|
message. If you want to do something with the draft messages after
|
|
|
|
|
it has been constructed, `mu4e-compose-mode-hook' would be the
|
2013-10-20 14:41:47 +02:00
|
|
|
|
place to do that."
|
|
|
|
|
:type 'hook
|
|
|
|
|
:group 'mu4e-compose)
|
2012-08-28 17:57:31 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-24 17:13:12 +02:00
|
|
|
|
|
|
|
|
|
|
2012-09-25 08:37:37 +02:00
|
|
|
|
(defun mu4e-compose-attach-captured-message ()
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Insert the last captured message file as an attachment.
|
|
|
|
|
Messages are captured with `mu4e-action-capture-message'."
|
2012-06-24 08:45:53 +02:00
|
|
|
|
(interactive)
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(unless mu4e-captured-message
|
2012-09-06 09:33:53 +02:00
|
|
|
|
(mu4e-warn "No message has been captured"))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(let ((path (plist-get mu4e-captured-message :path)))
|
|
|
|
|
(unless (file-exists-p path)
|
2012-09-06 09:33:53 +02:00
|
|
|
|
(mu4e-warn "Captured message file not found"))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(mml-attach-file
|
|
|
|
|
path
|
2012-09-25 08:37:37 +02:00
|
|
|
|
"message/rfc822"
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(or (plist-get mu4e-captured-message :subject) "No subject")
|
2012-07-22 23:55:12 +02:00
|
|
|
|
"attachment")))
|
2011-09-18 13:39:36 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2012-04-30 16:34:51 +02:00
|
|
|
|
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;; 'fcc' refers to saving a copy of a sent message to a certain folder. that's
|
|
|
|
|
;; what these 'Sent mail' folders are for!
|
|
|
|
|
;;
|
|
|
|
|
;; We let message mode take care of this by adding a field
|
2012-07-22 23:55:12 +02:00
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;; Fcc: <full-path-to-message-in-target-folder>
|
2012-07-22 23:55:12 +02:00
|
|
|
|
|
|
|
|
|
;; in the "message-send-hook" (ie., just before sending). message mode will
|
|
|
|
|
;; then take care of the saving when the message is actually sent.
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;;
|
|
|
|
|
;; note, where and if you make this copy depends on the value of
|
|
|
|
|
;; `mu4e-sent-messages-behavior'.
|
|
|
|
|
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(defun mu4e~compose-setup-fcc-maybe ()
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Maybe setup Fcc, based on `mu4e-sent-messages-behavior'.
|
|
|
|
|
If needed, set the Fcc header, and register the handler function."
|
2013-04-21 11:40:57 +02:00
|
|
|
|
(let* ((sent-behavior
|
2013-04-23 18:51:45 +02:00
|
|
|
|
;; Note; we cannot simply use functionp here, since at least
|
|
|
|
|
;; delete is a function, too...
|
|
|
|
|
(if (member mu4e-sent-messages-behavior '(delete trash sent))
|
|
|
|
|
mu4e-sent-messages-behavior
|
|
|
|
|
(if (functionp mu4e-sent-messages-behavior)
|
|
|
|
|
(funcall mu4e-sent-messages-behavior)
|
|
|
|
|
mu4e-sent-messages-behavior)))
|
2013-04-21 11:40:57 +02:00
|
|
|
|
(mdir
|
2013-04-23 18:51:45 +02:00
|
|
|
|
(case sent-behavior
|
|
|
|
|
(delete nil)
|
|
|
|
|
(trash (mu4e-get-trash-folder mu4e-compose-parent-message))
|
|
|
|
|
(sent (mu4e-get-sent-folder mu4e-compose-parent-message))
|
|
|
|
|
(otherwise
|
|
|
|
|
(mu4e-error "unsupported value '%S' `mu4e-sent-messages-behavior'."
|
2013-05-15 21:09:17 +02:00
|
|
|
|
mu4e-sent-messages-behavior))))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(fccfile (and mdir
|
|
|
|
|
(concat mu4e-maildir mdir "/cur/"
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(mu4e~draft-message-filename-construct "S")))))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;; if there's an fcc header, add it to the file
|
2013-04-23 18:51:45 +02:00
|
|
|
|
(when fccfile
|
|
|
|
|
(message-add-header (concat "Fcc: " fccfile "\n"))
|
|
|
|
|
;; sadly, we cannot define as 'buffer-local'... this will screw up gnus
|
2012-07-22 23:55:12 +02:00
|
|
|
|
;; etc. if you run it after mu4e so, (hack hack) we reset it to the old
|
2012-09-27 09:03:58 +02:00
|
|
|
|
;; handler after we've done our thing.
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(setq message-fcc-handler-function
|
|
|
|
|
(lexical-let ((maildir mdir) (old-handler message-fcc-handler-function))
|
|
|
|
|
(lambda (file)
|
|
|
|
|
(setq message-fcc-handler-function old-handler) ;; reset the fcc handler
|
2012-07-22 23:55:12 +02:00
|
|
|
|
(write-file file) ;; writing maildirs files is easy
|
2013-05-21 07:05:06 +02:00
|
|
|
|
(mu4e~proc-add file (or maildir "/")))))))) ;; update the database
|
2012-04-26 17:08:42 +02:00
|
|
|
|
|
2013-06-08 16:54:35 +02:00
|
|
|
|
(defvar mu4e-compose-hidden-headers
|
2013-05-26 11:35:14 +02:00
|
|
|
|
`("^References:" "^Face:" "^X-Face:"
|
|
|
|
|
"^X-Draft-From:" "^User-agent:")
|
|
|
|
|
"Hidden headers when composing.")
|
|
|
|
|
|
2013-06-08 16:54:35 +02:00
|
|
|
|
(defun mu4e~compose-hide-headers ()
|
|
|
|
|
"Hide the headers as per `mu4e-compose-hidden-headers'."
|
|
|
|
|
(let ((message-hidden-headers mu4e-compose-hidden-headers))
|
|
|
|
|
(message-hide-headers)))
|
|
|
|
|
|
2013-05-26 11:35:14 +02:00
|
|
|
|
(defconst mu4e~compose-address-fields-regexp
|
|
|
|
|
"^\\(To\\|B?Cc\\|Reply-To\\|From\\):")
|
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(defun mu4e~compose-register-message-save-hooks ()
|
|
|
|
|
"Just before saving, we remove the mail-header-separator; just
|
2012-11-10 14:01:17 +01:00
|
|
|
|
after saving we restore it; thus, the separator should never
|
|
|
|
|
appear on disk."
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(add-hook 'before-save-hook
|
2012-10-31 19:33:46 +01:00
|
|
|
|
'mu4e~draft-remove-mail-header-separator nil t)
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(add-hook 'after-save-hook
|
|
|
|
|
(lambda ()
|
|
|
|
|
(mu4e~compose-set-friendly-buffer-name)
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(mu4e~draft-insert-mail-header-separator)
|
2013-05-22 07:06:19 +02:00
|
|
|
|
;; hide some headers again
|
2013-06-08 16:54:35 +02:00
|
|
|
|
(mu4e~compose-hide-headers)
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(set-buffer-modified-p nil)
|
2015-03-21 14:23:35 +01:00
|
|
|
|
(mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max)))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;; update the file on disk -- ie., without the separator
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(mu4e~proc-add (buffer-file-name) mu4e~draft-drafts-folder)) nil t))
|
2011-10-02 20:35:03 +02:00
|
|
|
|
|
2012-06-23 17:13:53 +02:00
|
|
|
|
|
2014-11-30 15:29:10 +01:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; address completion; inspired by org-contacts.el and
|
|
|
|
|
;; https://github.com/nordlow/elisp/blob/master/mine/completion-styles-cycle.el
|
2012-06-24 15:34:01 +02:00
|
|
|
|
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(defun mu4e~compose-complete-contact (&optional start)
|
|
|
|
|
"Complete the text at START with a contact.
|
|
|
|
|
Ie. either 'name <email>' or 'email')."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((mail-abbrev-mode-regexp mu4e~compose-address-fields-regexp)
|
|
|
|
|
(eoh ;; end-of-headers
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(search-forward-regexp mail-header-separator nil t))))
|
|
|
|
|
;; try to complete only when we're in the headers area,
|
|
|
|
|
;; looking at an address field.
|
|
|
|
|
(when (and eoh (> eoh (point)) (mail-abbrev-in-expansion-header-p))
|
|
|
|
|
(let* ((end (point))
|
|
|
|
|
(start
|
|
|
|
|
(or start
|
|
|
|
|
(save-excursion
|
|
|
|
|
(re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
|
|
|
|
|
(goto-char (match-end 0))
|
|
|
|
|
(point)))))
|
|
|
|
|
(list start end mu4e~contacts-for-completion)))))
|
|
|
|
|
|
2012-06-22 08:45:06 +02:00
|
|
|
|
(defun mu4e~compose-setup-completion ()
|
2014-11-30 15:29:10 +01:00
|
|
|
|
"Set up auto-completion of addresses."
|
|
|
|
|
(set (make-local-variable 'completion-ignore-case) t)
|
|
|
|
|
(set (make-local-variable 'completion-cycle-threshold) 7)
|
2014-12-06 13:23:55 +01:00
|
|
|
|
(add-to-list (make-local-variable 'completion-styles) 'substring t)
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(add-hook 'completion-at-point-functions
|
|
|
|
|
'mu4e~compose-complete-contact nil t))
|
|
|
|
|
|
2015-11-22 11:17:36 +01:00
|
|
|
|
|
|
|
|
|
(defun mu4e~remove-refs-maybe ()
|
|
|
|
|
"Remove the References: header if the In-Reply-To header is
|
|
|
|
|
missing. This allows the user to effectively start a new
|
|
|
|
|
message-thread by removing the In-Reply-To header."
|
|
|
|
|
(unless (message-fetch-field "in-reply-to")
|
|
|
|
|
(message-remove-header "References")))
|
|
|
|
|
|
2014-11-30 15:29:10 +01:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
(defvar mu4e-compose-mode-map nil
|
|
|
|
|
"Keymap for \"*mu4e-compose*\" buffers.")
|
|
|
|
|
(unless mu4e-compose-mode-map
|
|
|
|
|
(setq mu4e-compose-mode-map
|
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
|
(define-key map (kbd "C-S-u") 'mu4e-update-mail-and-index)
|
|
|
|
|
(define-key map (kbd "C-c C-u") 'mu4e-update-mail-and-index)
|
|
|
|
|
map)))
|
2012-07-22 23:55:12 +02:00
|
|
|
|
|
2012-08-14 09:20:27 +02:00
|
|
|
|
(defvar mu4e-compose-mode-abbrev-table nil)
|
2012-04-23 19:35:14 +02:00
|
|
|
|
(define-derived-mode mu4e-compose-mode message-mode "mu4e:compose"
|
2012-04-11 21:31:52 +02:00
|
|
|
|
"Major mode for the mu4e message composition, derived from `message-mode'.
|
2012-03-28 00:47:52 +02:00
|
|
|
|
\\{message-mode-map}."
|
2013-06-16 22:06:38 +02:00
|
|
|
|
(progn
|
2012-04-23 19:35:14 +02:00
|
|
|
|
(use-local-map mu4e-compose-mode-map)
|
2015-12-19 09:14:49 +01:00
|
|
|
|
|
|
|
|
|
(set (make-local-variable 'global-mode-string) '(:eval (mu4e-context-label)))
|
|
|
|
|
|
2014-10-12 09:36:33 +02:00
|
|
|
|
(set (make-local-variable 'message-signature) mu4e-compose-signature)
|
|
|
|
|
;; set this to allow mu4e to work when gnus-agent is unplugged in gnus
|
|
|
|
|
(set (make-local-variable 'message-send-mail-real-function) nil)
|
2012-04-02 18:59:16 +02:00
|
|
|
|
(make-local-variable 'message-default-charset)
|
|
|
|
|
;; if the default charset is not set, use UTF-8
|
|
|
|
|
(unless message-default-charset
|
|
|
|
|
(setq message-default-charset 'utf-8))
|
2012-04-25 07:30:10 +02:00
|
|
|
|
;; make sure mu4e is started in the background (ie. we don't want to error
|
|
|
|
|
;; out when sending the message; better to do it now if there's a problem)
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(mu4e~start) ;; start mu4e in background, if needed
|
|
|
|
|
(mu4e~compose-register-message-save-hooks)
|
2012-03-28 17:58:43 +02:00
|
|
|
|
;; set the default directory to the user's home dir; this is probably more
|
|
|
|
|
;; useful e.g. when finding an attachment file the directory the current
|
|
|
|
|
;; mail files lives in...
|
2012-05-23 16:04:26 +02:00
|
|
|
|
(setq default-directory (expand-file-name "~/"))
|
2012-07-22 23:55:12 +02:00
|
|
|
|
|
2012-06-24 15:34:01 +02:00
|
|
|
|
;; offer completion for e-mail addresses
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(when mu4e-compose-complete-addresses
|
2012-06-22 08:45:06 +02:00
|
|
|
|
(mu4e~compose-setup-completion))
|
2012-07-22 23:55:12 +02:00
|
|
|
|
|
2012-05-23 16:04:26 +02:00
|
|
|
|
;; setup the fcc-stuff, if needed
|
|
|
|
|
(add-hook 'message-send-hook
|
2013-06-16 22:06:38 +02:00
|
|
|
|
(lambda () ;; mu4e~compose-save-before-sending
|
2015-11-22 11:17:36 +01:00
|
|
|
|
;; when in-reply-to was removed, remove references as well.
|
|
|
|
|
(mu4e~remove-refs-maybe)
|
2012-05-23 16:04:26 +02:00
|
|
|
|
;; for safety, always save the draft before sending
|
|
|
|
|
(set-buffer-modified-p t)
|
|
|
|
|
(save-buffer)
|
2013-06-14 07:42:44 +02:00
|
|
|
|
(mu4e~compose-setup-fcc-maybe)
|
|
|
|
|
(widen)) nil t)
|
2012-05-23 16:04:26 +02:00
|
|
|
|
;; when the message has been sent.
|
|
|
|
|
(add-hook 'message-sent-hook
|
2013-06-16 22:06:38 +02:00
|
|
|
|
(lambda () ;; mu4e~compose-mark-after-sending
|
2012-05-23 16:04:26 +02:00
|
|
|
|
(setq mu4e-sent-func 'mu4e-sent-handler)
|
2013-10-22 19:34:43 +02:00
|
|
|
|
(mu4e~proc-sent (buffer-file-name) mu4e~draft-drafts-folder)) nil t))
|
2012-10-29 11:27:32 +01:00
|
|
|
|
;; mark these two hooks as permanent-local, so they'll survive mode-changes
|
2013-06-08 16:54:35 +02:00
|
|
|
|
;; (put 'mu4e~compose-save-before-sending 'permanent-local-hook t)
|
2012-10-29 11:27:32 +01:00
|
|
|
|
(put 'mu4e~compose-mark-after-sending 'permanent-local-hook t))
|
2012-03-28 00:47:52 +02:00
|
|
|
|
|
2012-04-23 19:35:14 +02:00
|
|
|
|
(defconst mu4e~compose-buffer-max-name-length 30
|
2012-04-01 20:36:13 +02:00
|
|
|
|
"Maximum length of the mu4e-send-buffer-name.")
|
|
|
|
|
|
2012-04-23 19:35:14 +02:00
|
|
|
|
(defun mu4e~compose-set-friendly-buffer-name (&optional compose-type)
|
2012-04-01 20:36:13 +02:00
|
|
|
|
"Set some user-friendly buffer name based on the compose type."
|
|
|
|
|
(let* ((subj (message-field-value "subject"))
|
|
|
|
|
(subj (unless (and subj (string-match "^[:blank:]*$" subj)) subj))
|
|
|
|
|
(str (or subj
|
|
|
|
|
(case compose-type
|
|
|
|
|
(reply "*reply*")
|
|
|
|
|
(forward "*forward*")
|
|
|
|
|
(otherwise "*draft*")))))
|
|
|
|
|
(rename-buffer (generate-new-buffer-name
|
|
|
|
|
(truncate-string-to-width str
|
2012-04-23 19:35:14 +02:00
|
|
|
|
mu4e~compose-buffer-max-name-length
|
2012-04-01 20:36:13 +02:00
|
|
|
|
nil nil t)))))
|
2013-06-16 22:06:38 +02:00
|
|
|
|
|
2014-06-18 15:33:55 +02:00
|
|
|
|
(defun* mu4e~compose-handler (compose-type &optional original-msg includes)
|
2012-04-16 19:54:58 +02:00
|
|
|
|
"Create a new draft message, or open an existing one.
|
2011-10-02 20:35:03 +02:00
|
|
|
|
|
|
|
|
|
COMPOSE-TYPE determines the kind of message to compose and is a
|
|
|
|
|
symbol, either `reply', `forward', `edit', `new'. `edit' is for
|
2012-09-27 09:03:58 +02:00
|
|
|
|
editing existing messages. When COMPOSE-TYPE is `reply' or
|
|
|
|
|
`forward', MSG should be a message plist. If COMPOSE-TYPE is
|
|
|
|
|
`new', ORIGINAL-MSG should be nil.
|
2011-10-02 20:35:03 +02:00
|
|
|
|
|
2012-01-14 11:55:50 +01:00
|
|
|
|
Optionally (when forwarding, replying) ORIGINAL-MSG is the original
|
|
|
|
|
message we will forward / reply to.
|
|
|
|
|
|
|
|
|
|
Optionally (when forwarding) INCLUDES contains a list of
|
|
|
|
|
(:file-name <filename> :mime-type <mime-type> :disposition <disposition>)
|
|
|
|
|
for the attachements to include; file-name refers to
|
|
|
|
|
a file which our backend has conveniently saved for us (as a
|
2012-09-27 09:03:58 +02:00
|
|
|
|
tempfile)."
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
2012-10-01 15:43:47 +02:00
|
|
|
|
;; Run the hooks defined for `mu4e-compose-pre-hook'. If compose-type is
|
|
|
|
|
;; `reply', `forward' or `edit', `mu4e-compose-parent-message' points to the
|
|
|
|
|
;; message being forwarded or replied to, otherwise it is nil.
|
2012-10-01 20:18:06 +02:00
|
|
|
|
(set (make-local-variable 'mu4e-compose-parent-message) original-msg)
|
|
|
|
|
(put 'mu4e-compose-parent-message 'permanent-local t)
|
2015-12-13 16:43:41 +01:00
|
|
|
|
(let ((context (mu4e-context-determine mu4e-compose-parent-message)))
|
2015-12-16 15:32:29 +01:00
|
|
|
|
(if context
|
|
|
|
|
(mu4e-context-switch (mu4e-context-name context))
|
|
|
|
|
(when mu4e-contexts (mu4e-context-switch))))
|
2012-10-29 11:27:32 +01:00
|
|
|
|
(run-hooks 'mu4e-compose-pre-hook)
|
|
|
|
|
|
2012-09-27 09:03:58 +02:00
|
|
|
|
;; this opens (or re-opens) a messages with all the basic headers set.
|
2014-06-18 15:33:55 +02:00
|
|
|
|
(condition-case nil
|
|
|
|
|
(mu4e-draft-open compose-type original-msg)
|
|
|
|
|
(quit (kill-buffer) (message "[mu4e] Operation aborted")
|
|
|
|
|
(return-from mu4e~compose-handler)))
|
2012-09-27 09:03:58 +02:00
|
|
|
|
;; insert mail-header-separator, which is needed by message mode to separate
|
|
|
|
|
;; headers and body. will be removed before saving to disk
|
2012-10-31 19:33:46 +01:00
|
|
|
|
(mu4e~draft-insert-mail-header-separator)
|
2012-09-27 09:03:58 +02:00
|
|
|
|
;; include files -- e.g. when forwarding a message with attachments,
|
|
|
|
|
;; we take those from the original.
|
|
|
|
|
(save-excursion
|
|
|
|
|
(goto-char (point-max)) ;; put attachments at the end
|
|
|
|
|
(dolist (att includes)
|
|
|
|
|
(mml-attach-file
|
|
|
|
|
(plist-get att :file-name) (plist-get att :mime-type))))
|
|
|
|
|
;; buffer is not user-modified yet
|
|
|
|
|
(mu4e~compose-set-friendly-buffer-name compose-type)
|
|
|
|
|
(set-buffer-modified-p nil)
|
|
|
|
|
;; now jump to some useful positions, and start writing that mail!
|
|
|
|
|
(if (member compose-type '(new forward))
|
|
|
|
|
(message-goto-to)
|
|
|
|
|
(message-goto-body))
|
2012-12-15 11:01:50 +01:00
|
|
|
|
;; bind to `mu4e-compose-parent-message' of compose buffer
|
|
|
|
|
(set (make-local-variable 'mu4e-compose-parent-message) original-msg)
|
|
|
|
|
(put 'mu4e-compose-parent-message 'permanent-local t)
|
2013-05-21 07:05:06 +02:00
|
|
|
|
;; hide some headers
|
2013-06-08 16:54:35 +02:00
|
|
|
|
(mu4e~compose-hide-headers)
|
2012-09-25 06:10:41 +02:00
|
|
|
|
;; switch on the mode
|
2013-10-20 14:41:47 +02:00
|
|
|
|
(mu4e-compose-mode))
|
2014-10-15 01:42:57 +02:00
|
|
|
|
|
2012-03-27 20:15:47 +02:00
|
|
|
|
(defun mu4e-sent-handler (docid path)
|
|
|
|
|
"Handler function, called with DOCID and PATH for the just-sent
|
2012-06-04 12:10:56 +02:00
|
|
|
|
message. For Forwarded ('Passed') and Replied messages, try to set
|
|
|
|
|
the appropriate flag at the message forwarded or replied-to."
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(mu4e~compose-set-parent-flag path)
|
|
|
|
|
(when (file-exists-p path) ;; maybe the draft was not saved at all
|
2012-06-14 08:57:47 +02:00
|
|
|
|
(mu4e~proc-remove docid))
|
|
|
|
|
;; kill any remaining buffers for the draft file, or they will hang around...
|
|
|
|
|
;; this seems a bit hamfisted...
|
|
|
|
|
(dolist (buf (buffer-list))
|
|
|
|
|
(when (and (buffer-file-name buf)
|
2015-06-07 12:56:02 +02:00
|
|
|
|
(string= (buffer-file-name buf) path))
|
2014-09-24 16:06:26 +02:00
|
|
|
|
(if (and mu4e-compose-in-new-frame (window-system))
|
|
|
|
|
(progn
|
|
|
|
|
(switch-to-buffer buf)
|
|
|
|
|
(when (and (get-buffer-window buf)
|
|
|
|
|
(window-frame (get-buffer-window buf)))
|
2015-05-25 15:50:33 +02:00
|
|
|
|
(delete-frame (window-frame (get-buffer-window buf)))))
|
2015-06-07 12:56:02 +02:00
|
|
|
|
)
|
|
|
|
|
(if message-kill-buffer-on-exit
|
|
|
|
|
(kill-buffer buf))
|
|
|
|
|
))
|
2013-01-04 20:40:12 +01:00
|
|
|
|
;; now, try to go back to some previous buffer, in the order
|
|
|
|
|
;; view->headers->main
|
|
|
|
|
(if (buffer-live-p mu4e~view-buffer)
|
2014-03-28 13:38:46 +01:00
|
|
|
|
(switch-to-buffer mu4e~view-buffer)
|
|
|
|
|
(if (buffer-live-p mu4e~headers-buffer)
|
|
|
|
|
(switch-to-buffer mu4e~headers-buffer)
|
|
|
|
|
;; if all else fails, back to the main view
|
|
|
|
|
(when (fboundp 'mu4e) (mu4e))))
|
2012-06-14 08:57:47 +02:00
|
|
|
|
(mu4e-message "Message sent"))
|
2012-03-28 17:58:43 +02:00
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(defun mu4e~compose-set-parent-flag (path)
|
2012-03-27 20:15:47 +02:00
|
|
|
|
"Set the 'replied' \"R\" flag on messages we replied to, and the
|
|
|
|
|
'passed' \"F\" flag on message we have forwarded.
|
2011-09-18 13:39:36 +02:00
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
If a message has an 'in-reply-to' header, it is considered a reply
|
2011-10-02 20:35:03 +02:00
|
|
|
|
to the message with the corresponding message id. If it does not
|
|
|
|
|
have an 'in-reply-to' header, but does have a 'references' header,
|
|
|
|
|
it is considered to be a forward message for the message
|
|
|
|
|
corresponding with the /last/ message-id in the references header.
|
2011-09-30 07:37:47 +02:00
|
|
|
|
|
2011-10-02 20:35:03 +02:00
|
|
|
|
Now, if the message has been determined to be either a forwarded
|
|
|
|
|
message or a reply, we instruct the server to update that message
|
|
|
|
|
with resp. the 'P' (passed) flag for a forwarded message, or the
|
2013-05-27 13:58:47 +02:00
|
|
|
|
'R' flag for a replied message. The original messages are also
|
|
|
|
|
marked as Seen.
|
2012-03-28 17:58:43 +02:00
|
|
|
|
|
|
|
|
|
Function assumes that it's executed in the context of the message
|
2012-04-26 17:08:42 +02:00
|
|
|
|
buffer."
|
|
|
|
|
(let ((buf (find-file-noselect path)))
|
|
|
|
|
(when buf
|
|
|
|
|
(with-current-buffer buf
|
|
|
|
|
(let ((in-reply-to (message-fetch-field "in-reply-to"))
|
|
|
|
|
(forwarded-from)
|
|
|
|
|
(references (message-fetch-field "references")))
|
|
|
|
|
(unless in-reply-to
|
|
|
|
|
(when references
|
|
|
|
|
(with-temp-buffer ;; inspired by `message-shorten-references'.
|
|
|
|
|
(insert references)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(let ((refs))
|
|
|
|
|
(while (re-search-forward "<[^ <]+@[^ <]+>" nil t)
|
|
|
|
|
(push (match-string 0) refs))
|
|
|
|
|
;; the last will be the first
|
|
|
|
|
(setq forwarded-from (first refs))))))
|
|
|
|
|
;; remove the <>
|
|
|
|
|
(when (and in-reply-to (string-match "<\\(.*\\)>" in-reply-to))
|
2013-05-27 13:58:47 +02:00
|
|
|
|
(mu4e~proc-move (match-string 1 in-reply-to) nil "+R-N"))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from))
|
2013-05-27 13:58:47 +02:00
|
|
|
|
(mu4e~proc-move (match-string 1 forwarded-from) nil "+P-N")))))))
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
2012-05-01 21:45:54 +02:00
|
|
|
|
(defun mu4e-compose (compose-type)
|
|
|
|
|
"Start composing a message of COMPOSE-TYPE, where COMPOSE-TYPE is
|
|
|
|
|
a symbol, one of `reply', `forward', `edit', `new'. All but `new'
|
|
|
|
|
take the message at point as input. Symbol `edit' is only allowed
|
|
|
|
|
for draft messages."
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(let ((msg (mu4e-message-at-point 'noerror)))
|
|
|
|
|
;; some sanity checks
|
|
|
|
|
(unless (or msg (eq compose-type 'new))
|
|
|
|
|
(mu4e-warn "No message at point"))
|
|
|
|
|
(unless (member compose-type '(reply forward edit new))
|
2012-09-28 16:10:34 +02:00
|
|
|
|
(mu4e-error "Invalid compose type '%S'" compose-type))
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(when (and (eq compose-type 'edit)
|
|
|
|
|
(not (member 'draft (mu4e-message-field msg :flags))))
|
|
|
|
|
(mu4e-warn "Editing is only allowed for draft messages"))
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
2012-10-01 15:43:47 +02:00
|
|
|
|
;; 'new is special, since it takes no existing message as arg; therefore, we
|
|
|
|
|
;; don't need to involve the backend, and call the handler *directly*
|
2012-09-26 16:28:30 +02:00
|
|
|
|
(if (eq compose-type 'new)
|
|
|
|
|
(mu4e~compose-handler 'new)
|
|
|
|
|
;; otherwise, we need the doc-id
|
2014-10-15 01:42:57 +02:00
|
|
|
|
(let* ((docid (mu4e-message-field msg :docid))
|
|
|
|
|
;; decrypt (or not), based on `mu4e-decryption-policy'.
|
|
|
|
|
(decrypt
|
|
|
|
|
(and (member 'encrypted (mu4e-message-field msg :flags))
|
|
|
|
|
(if (eq mu4e-decryption-policy 'ask)
|
|
|
|
|
(yes-or-no-p (mu4e-format "Decrypt message?"))
|
|
|
|
|
mu4e-decryption-policy))))
|
2012-09-26 16:28:30 +02:00
|
|
|
|
;; if there's a visible view window, select that before starting composing
|
|
|
|
|
;; a new message, so that one will be replaced by the compose window. The
|
|
|
|
|
;; 10-or-so line headers buffer is not a good place to write it...
|
2012-05-01 21:45:54 +02:00
|
|
|
|
(let ((viewwin (get-buffer-window mu4e~view-buffer)))
|
|
|
|
|
(when (window-live-p viewwin)
|
|
|
|
|
(select-window viewwin)))
|
2012-09-26 16:28:30 +02:00
|
|
|
|
;; talk to the backend
|
2014-10-15 01:42:57 +02:00
|
|
|
|
(mu4e~proc-compose compose-type decrypt docid)))))
|
2012-05-01 21:45:54 +02:00
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-reply ()
|
|
|
|
|
"Compose a reply for the message at point in the headers buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-compose 'reply))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-forward ()
|
|
|
|
|
"Forward the message at point in the headers buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-compose 'forward))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-edit ()
|
2012-11-10 14:01:17 +01:00
|
|
|
|
"Edit the draft message at point in the headers buffer.
|
|
|
|
|
This is only possible if the message at point is, in fact, a
|
|
|
|
|
draft message."
|
2012-05-01 21:45:54 +02:00
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-compose 'edit))
|
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-new ()
|
|
|
|
|
"Start writing a new message."
|
|
|
|
|
(interactive)
|
|
|
|
|
(mu4e-compose 'new))
|
|
|
|
|
|
2012-06-18 17:03:24 +02:00
|
|
|
|
|
2012-04-19 07:30:42 +02:00
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
;; mu4e-compose-func and mu4e-send-func are wrappers so we can set ourselves
|
|
|
|
|
;; as default emacs mailer (define-mail-user-agent etc.)
|
|
|
|
|
|
2012-11-14 12:55:15 +01:00
|
|
|
|
;;;###autoload
|
2012-05-01 21:45:54 +02:00
|
|
|
|
(defun mu4e~compose-mail (&optional to subject other-headers continue
|
|
|
|
|
switch-function yank-action send-actions return-action)
|
2012-09-27 09:03:58 +02:00
|
|
|
|
"This is mu4e's implementation of `compose-mail'."
|
2012-10-29 11:27:32 +01:00
|
|
|
|
|
2012-04-25 07:30:10 +02:00
|
|
|
|
;; create a new draft message 'resetting' (as below) is not actually needed in
|
|
|
|
|
;; this case, but let's prepare for the re-edit case as well
|
2012-04-23 20:16:20 +02:00
|
|
|
|
(mu4e~compose-handler 'new)
|
2012-05-10 16:09:57 +02:00
|
|
|
|
|
2012-04-25 07:30:10 +02:00
|
|
|
|
(when (message-goto-to) ;; reset to-address, if needed
|
|
|
|
|
(message-delete-line))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(message-add-header (concat "To: " to "\n"))
|
|
|
|
|
|
2012-04-25 07:30:10 +02:00
|
|
|
|
(when (message-goto-subject) ;; reset subject, if needed
|
|
|
|
|
(message-delete-line))
|
2012-04-26 17:08:42 +02:00
|
|
|
|
(message-add-header (concat "Subject: " subject "\n"))
|
|
|
|
|
|
2012-05-10 16:09:57 +02:00
|
|
|
|
;; add any other headers specified
|
2012-04-25 07:30:10 +02:00
|
|
|
|
(when other-headers
|
|
|
|
|
(message-add-header other-headers))
|
|
|
|
|
|
2012-04-19 17:54:31 +02:00
|
|
|
|
;; yank message
|
2012-04-19 07:30:42 +02:00
|
|
|
|
(if (bufferp yank-action)
|
|
|
|
|
(list 'insert-buffer yank-action)
|
2012-04-25 07:30:10 +02:00
|
|
|
|
yank-action)
|
|
|
|
|
|
|
|
|
|
;; try to put the user at some reasonable spot...
|
|
|
|
|
(if (not to)
|
|
|
|
|
(message-goto-to)
|
|
|
|
|
(if (not subject)
|
|
|
|
|
(message-goto-subject)
|
|
|
|
|
(message-goto-body))))
|
2012-04-19 07:30:42 +02:00
|
|
|
|
|
2012-04-19 17:54:31 +02:00
|
|
|
|
;; happily, we can re-use most things from message mode
|
2012-11-14 12:55:15 +01:00
|
|
|
|
;;;###autoload
|
2012-04-19 07:30:42 +02:00
|
|
|
|
(define-mail-user-agent 'mu4e-user-agent
|
2012-05-01 21:45:54 +02:00
|
|
|
|
'mu4e~compose-mail
|
2012-04-19 07:30:42 +02:00
|
|
|
|
'message-send-and-exit
|
|
|
|
|
'message-kill-buffer
|
|
|
|
|
'message-send-hook)
|
2012-11-14 12:39:37 +01:00
|
|
|
|
;; Without this `mail-user-agent' cannot be set to `mu4e-user-agent'
|
|
|
|
|
;; through customize, as the custom type expects a function. Not
|
|
|
|
|
;; sure whether this function is actually ever used; if it is then
|
|
|
|
|
;; returning the symbol is probably the correct thing to do, as other
|
|
|
|
|
;; such functions suggest.
|
|
|
|
|
(defun mu4e-user-agent ()
|
|
|
|
|
'mu4e-user-agent)
|
2012-04-19 07:30:42 +02:00
|
|
|
|
|
2012-06-19 13:12:54 +02:00
|
|
|
|
(defun mu4e~compose-browse-url-mail (url &optional ignored)
|
|
|
|
|
"Adapter for `browse-url-mailto-function."
|
|
|
|
|
(let* ((headers (rfc2368-parse-mailto-url url))
|
|
|
|
|
(to (cdr (assoc "To" headers)))
|
|
|
|
|
(subject (cdr (assoc "Subject" headers)))
|
|
|
|
|
(body (cdr (assoc "Body" headers))))
|
|
|
|
|
(mu4e~compose-mail to subject)
|
|
|
|
|
(if body
|
|
|
|
|
(progn
|
|
|
|
|
(message-goto-body)
|
|
|
|
|
(insert body)
|
|
|
|
|
(if (not to)
|
|
|
|
|
(message-goto-to)
|
|
|
|
|
(if (not subject)
|
|
|
|
|
(message-goto-subject)
|
|
|
|
|
(message-goto-body)))))))
|
2012-06-21 20:19:29 +02:00
|
|
|
|
|
2012-04-26 17:08:42 +02:00
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2014-01-09 18:07:48 +01:00
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-goto-top ()
|
|
|
|
|
"Go to the beginning of the message or buffer.
|
|
|
|
|
Go to the beginning of the message or, if already there, go to the
|
|
|
|
|
beginning of the buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((old-position (point)))
|
|
|
|
|
(message-goto-body)
|
|
|
|
|
(when (equal (point) old-position)
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(goto-char (point-min)))))
|
2014-01-09 18:07:48 +01:00
|
|
|
|
|
|
|
|
|
(define-key mu4e-compose-mode-map
|
|
|
|
|
(vector 'remap 'beginning-of-buffer) 'mu4e-compose-goto-top)
|
|
|
|
|
|
|
|
|
|
(defun mu4e-compose-goto-bottom ()
|
|
|
|
|
"Go to the end of the message or buffer.
|
|
|
|
|
Go to the end of the message (before signature) or, if already there, go to the
|
|
|
|
|
end of the buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((old-position (point))
|
|
|
|
|
(message-position (save-excursion (message-goto-body) (point))))
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(goto-char (point-max))
|
2014-01-09 18:18:36 +01:00
|
|
|
|
(when (re-search-backward message-signature-separator message-position t)
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(forward-line -1))
|
2014-01-09 18:07:48 +01:00
|
|
|
|
(when (equal (point) old-position)
|
2014-11-30 15:29:10 +01:00
|
|
|
|
(goto-char (point-max)))))
|
2014-01-09 18:07:48 +01:00
|
|
|
|
|
|
|
|
|
(define-key mu4e-compose-mode-map
|
|
|
|
|
(vector 'remap 'end-of-buffer) 'mu4e-compose-goto-bottom)
|
|
|
|
|
|
2015-11-22 11:17:36 +01:00
|
|
|
|
|
|
|
|
|
|
2012-05-25 15:51:23 +02:00
|
|
|
|
(provide 'mu4e-compose)
|
2012-11-14 12:55:15 +01:00
|
|
|
|
|
|
|
|
|
;; Load mu4e completely even when this file was loaded through
|
|
|
|
|
;; autoload.
|
|
|
|
|
(require 'mu4e)
|