Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* mml-attach-file always at the end of the buffer
@ 2015-03-23  2:48 SF
  0 siblings, 0 replies; only message in thread
From: SF @ 2015-03-23  2:48 UTC (permalink / raw)
  To: info-gnus-english

Hi,

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.

  Sebastian



(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)."
  (interactive
   (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)) (point))))
    (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))))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-23  2:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-23  2:48 mml-attach-file always at the end of the buffer SF

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).