info-gnus-english
[Top][All Lists]
Advanced

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

Re: delayed sending of mail


From: Kevin Brubeck Unhammer
Subject: Re: delayed sending of mail
Date: Thu, 23 Aug 2012 11:04:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

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: pgpivoeEjZpYh.pgp
Description: PGP signature


reply via email to

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