Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Kevin Brubeck Unhammer <unhammer@fsfe.org>
To: info-gnus-english@gnu.org
Subject: Re: delayed sending of mail
Date: Thu, 23 Aug 2012 11:04:08 +0200	[thread overview]
Message-ID: <87y5l6ughj.fsf@fsfe.org> (raw)
In-Reply-To: <87fw7e4p7e.fsf@topper.koldfront.dk>


[-- Attachment #1.1: Type: text/plain, Size: 4469 bytes --]

asjo@koldfront.dk (Adam Sjøgren) writes:

> On Wed, 22 Aug 2012 15:06:26 +0200, Kevin wrote:
>
>> someone on IRC asked about how to make a function that delays sending of
>> email, so as to have a chance to edit/cancel within 2 minutes or so.
>
> When I want delayed sending of an email/article, instead of using C-c
> C-c to send it, I go C-c C-j (which is bound to gnus-delay-article).
>
> Then I am prompted about how long to delay it, or when to send it. After
> answering that, the email shows up in nndraft:delayed until the set
> time, when it is sent.
>
> In my .gnus I have these things to make it work:
>
>     ; Activate delayed messages:
>     (gnus-delay-initialize)
>
>     ; Show X-Now-Playing and X-Gnus-Delayed header:
>     (setq gnus-visible-headers (concat gnus-visible-headers "\\|^X-Now-Playing:\\|X-Gnus-Delayed:"))
>
>     ; Remove date, so delayed messages (C-c C-j) don't get a date until
>     ; sent <mailman.1180.1266014215.14305.info-gnus-english@gnu.org>:
>     (setq message-draft-headers '(References From))
>
> Only the first one is essential, I think. Oh, and the documentation of
> gnus-delay-article says that delayed messages are sent after new news is
> fetched, which means that these lines in my .gnus:
>
>     ; Demon to fetch email every 5 minutes when Emacs has been idle for 5 minutes:
>     (gnus-demon-add-handler 'gnus-demon-scan-news 5 5)
>     (gnus-demon-init)
>
> probably are essential as well. (And sending is potentially ~5 minutes
> off.)
>
> Maybe you can build upon gnus-delay-article if you want a fixed delay?

Thanks, Adam and Reiner, I should've guessed it was solved already :)


I prefer a shorter demon timeout for this purpose, but I don't need the
full news scan, so I used

    (gnus-demon-add-handler 'gnus-delay-send-queue 1 nil) ; call every other minute regardless of idleness
    (gnus-demon-init)

And for the actual sending, in case anyone's interested:

    (defvar message-delayed-send-default-minutes 2
      "Default delay in minutes before delayed-sending with `message-delayed-send-and-exit'")

    (defun message-delayed-send-and-exit ()
      "Use `gnus-delay-article' to send after
    `message-delayed-send-default-minutes' minutes."
      (interactive)
      (message "Sending in %s minutes" message-delayed-send-default-minutes)
      (gnus-delay-article (format "%sm" message-delayed-send-default-minutes)))

    (define-key message-mode-map (kbd "C-c C-c") 'message-delayed-send-and-exit)

And in case I exit gnus before it's sent, I added:

    (defun gnus-delay-send-queue-hurry ()
      "As `gnus-delay-send-queue, but also send anything that is to
    be sent within `message-delayed-send-default-minutes minutes."
      (interactive)
      (save-excursion
        (let* ((group (format "nndraft:%s" gnus-delay-group))
    	   (message-send-hook (copy-sequence message-send-hook))
    	   articles
    	   article deadline)
          (when (gnus-group-entry group)
    	(gnus-activate-group group)
    	(add-hook 'message-send-hook
    		  (lambda () (message-remove-header gnus-delay-header)))
    	(setq articles (nndraft-articles))
    	(while (setq article (pop articles))
    	  (gnus-request-head article group)
    	  (set-buffer nntp-server-buffer)
    	  (goto-char (point-min))
    	  (if (re-search-forward
    	       (concat "^" (regexp-quote gnus-delay-header) ":\\s-+")
    	       nil t)
    	      (progn
    		(setq deadline (nnheader-header-value))
    		(setq deadline (apply 'encode-time
    				      (parse-time-string deadline)))
    		;; The difference:
		(setq deadline (time-subtract
				deadline
				(seconds-to-time
				 (* 60 message-delayed-send-default-minutes))))
    		(setq deadline (time-since deadline))
    		(when (and (>= (nth 0 deadline) 0)
    			   (>= (nth 1 deadline) 0))
    		  (message "Sending delayed article %d" article)
    		  (gnus-draft-send article group)
    		  (message "Sending delayed article %d...done" article)))
    	    (message "Delay header missing for article %d" article)))))))
    
    (add-hook 'gnus-exit-gnus-hook 'gnus-delay-send-queue-hurry)


(I guess another possibility would be to first go through nndraft and
alter the header, then call `gnus-delay-send-queue', but most of that
function consists of finding delayed articles anyway …)

-- 
Kevin Brubeck Unhammer

GPG: 0x766AC60C

[-- Attachment #1.2: Type: application/pgp-signature, Size: 489 bytes --]

[-- Attachment #2: Type: text/plain, Size: 162 bytes --]

_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

  parent reply	other threads:[~2012-08-23  9:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-22 13:06 Kevin Brubeck Unhammer
2012-08-22 21:00 ` Adam Sjøgren
2012-08-22 21:04   ` Adam Sjøgren
2012-08-23  9:04   ` Kevin Brubeck Unhammer [this message]
2012-08-23 10:25     ` Adam Sjøgren
2012-08-22 21:01 ` Reiner Steib

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=87y5l6ughj.fsf@fsfe.org \
    --to=unhammer@fsfe.org \
    --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).