Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: SF <sebastian.fischmeister@gmail.com>
To: info-gnus-english@gnu.org
Subject: mml-attach-file always at the end of the buffer
Date: Sun, 22 Mar 2015 19:48:36 -0700 (PDT)	[thread overview]
Message-ID: <5a71fcaf-e84f-41fb-ab4c-d7adc4be9c83@googlegroups.com> (raw)

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))))

                 reply	other threads:[~2015-03-23  2:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a71fcaf-e84f-41fb-ab4c-d7adc4be9c83@googlegroups.com \
    --to=sebastian.fischmeister@gmail.com \
    --cc=info-gnus-english@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).