Gnus development mailing list
 help / color / mirror / Atom feed
From: Bob Newell <bobnewell@bobnewell.net>
To: ding@gnus.org
Subject: gnus and Gmail: saving drafts to Gmail draft folder
Date: Sun, 05 Mar 2017 09:45:20 -1000	[thread overview]
Message-ID: <87mvczcxtb.fsf@bobnewell.net> (raw)
In-Reply-To: <86y3x8ssi7.fsf@reader.local.lan> (Harry Putnam's message of "Tue, 14 Feb 2017 10:26:40 -0500")

I don't want to save drafts (with C-c C-d) to a local draft folder; I
want them to go to the [Gmail]/Drafts folder. Everything I found on the
net said that this wasn't an option. So I kludged up a workaround. It
undoubtedly has downsides and could be done better, so any constructive
feedback is welcome.

----
;; Move drafts to the gmail draft folder.
(defun gmail-move-drafts ()
  "Move all local drafts to Gmail draft folder"
  (interactive)

  ;; Better than 'let' for debugging.
  (defvar gmail-draft-saved-hooks)

  ;; This avoids an error when using the gnus registry.
  ;; It is not ideal. Is there a better way?
  (setq gmail-draft-saved-hooks gnus-summary-article-move-hook)
  (setq gnus-summary-article-move-hook nil)

  ;; The long way around. If there is a group buffer go there.
  ;; If there is a draft folder, go there. (There ought to be but...)
  ;; Mark all the draft messages.
  ;; Move them to Gmail.
  ;; Be /sure/ to exit the summary buffer!
  ;; Return to the buffer from whence we came.
  ;; Restore the hooks.
  (if (get-buffer "*Group*")
      (with-current-buffer "*Group*"
	 (if (gnus-group-goto-group "nndraft:drafts" t)
	       (if (or (gnus-group-select-group) (gnus-topic-select-group))
		   (progn
		      (gnus-uu-mark-buffer)
		      (gnus-summary-move-article nil "nnimap+gmail:[Gmail]/Drafts" nil)
		      (gnus-summary-exit))))))
  (setq gnus-summary-article-move-hook gmail-draft-saved-hooks))

;; Make our function run after saving a draft.
(advice-add 'message-dont-send :after #'gmail-move-drafts)

-- 
Bob Newell
Honolulu, Hawai`i
* Via Gnus/BBDB/Org/Emacs/Linux *



      parent reply	other threads:[~2017-03-05 19:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14 15:26 hefty paused when press `g' and other commands Harry Putnam
2017-02-14 19:28 ` Bob Newell
2017-03-05  1:23   ` Harry Putnam
2017-03-05 19:45 ` Bob Newell [this message]

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=87mvczcxtb.fsf@bobnewell.net \
    --to=bobnewell@bobnewell.net \
    --cc=ding@gnus.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).