[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mml-attach-file always at the end of the buffer

From: SF
Subject: mml-attach-file always at the end of the buffer
Date: Sun, 22 Mar 2015 19:48:36 -0700 (PDT)
User-agent: G2/1.0


For some time already, I wanted to extend mml-attach-file, so it always 
attaches the file at the end of the buffer.

I'm sure this could also be done with a defadvice to move to the end of the 
buffer and then return upon exit, nevertheless here's my solution for it, since 
I haven't tinkered yet a lot with defadvice.


(setq mml-attach-files-at-end t)

(defun mml-attach-file (file &optional type description disposition)
  "Attach a file to the outgoing MIME message.
The file is not inserted or encoded until you send the message with
`\\[message-send-and-exit]' or `\\[message-send]' in Message mode,
or `\\[mail-send-and-exit]' or `\\[mail-send]' in Mail mode.

FILE is the name of the file to attach.  TYPE is its
content-type, a string of the form \"type/subtype\".  DESCRIPTION
is a one-line description of the attachment.  The DISPOSITION
specifies how the attachment is intended to be displayed.  It can
be either \"inline\" (displayed automatically within the message
body) or \"attachment\" (separate from the body)."
   (let* ((file (mml-minibuffer-read-file "Attach file: "))
          (type (mml-minibuffer-read-type file))
          (description (mml-minibuffer-read-description))
          (disposition (mml-minibuffer-read-disposition type nil file)))
     (list file type description disposition)))
  ;; If in the message header, attach at the end and leave point unchanged.
  (let ((head (unless (and (message-in-body-p) (not mml-attach-files-at-end)) 
    (if (or head mml-attach-files-at-end) (goto-char (point-max)))
    (mml-insert-empty-tag 'part
                          'type type
                          ;; icicles redefines read-file-name and returns a
                          ;; string w/ text properties :-/
                          'filename (mm-substring-no-properties file)
                          'disposition (or disposition "attachment")
                          'description description)
    ;; When using Mail mode, make sure it does the mime encoding
    ;; when you send the message.
    (or (eq mail-user-agent 'message-user-agent)
        (setq mail-encode-mml t))
    (when (or head mml-attach-files-at-end)
      (unless (pos-visible-in-window-p)
        (message "The file \"%s\" has been attached at the end of the message"
                 (file-name-nondirectory file)))
      (goto-char head))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]