IMAP with server deletion

Tomas Nordin tomasn at posteo.net
Fri Jul 5 14:57:58 PDT 2019


Sam Halliday <sam.halliday at gmail.com> writes:

> Hello all,

Hello Sam

> I'm using emacs + notmuch + offlineimap + msmtp to manage my Gmail.

I have that setup apart from Gmail, (I use Posteo).

>
> My gmail account is starting to get so big that an offline sync is
>time
> consuming.
>
> I'd like to delete messages on the server, but keep them locally. Is
> that possible with IMAP?

Yes. I keep a lot of mailing list mails locally but delete them from the
server. I have this to tag list mails

(define-key notmuch-show-mode-map "a"
  (lambda ()
    "Tag all messages in current buffer with `rfile'."
    (interactive)
    (notmuch-show-tag-all (list "+rfile" "-inbox"))
    (message "rfiled the thread")))

so they all get tagged "rfile", just a tag I made up at some point. Then
I have this to move those messages to a directory not synced by
offlineimap:

(defun tn-refile-rfiles ()
  "Move all messages thus tagged to archive folder.

See variable `tn-refile-tags' for message tags that mean to move
the message to archived folder.

Discard all messages already in the archive folder."
  (interactive)
  (let (file-to-move count)
    (setq count 0)
    (message "Moving messages...")
    (dolist (file-to-move
	         (apply 'process-lines (append
                                    '("notmuch" "search" "--output=files")
				                    tn-refile-tags
				                    '("AND NOT folder:archive"))))
      (rename-file file-to-move
                   (concat tn-archive-folder
			               (file-name-nondirectory file-to-move)))
      (setq count (1+ count)))
    (if (> count 0)
	    (call-process "notmuch" nil "*tn-notmuch-new-out*" nil "new"))
    (message "Moved %d messages" count)))

The variable `tn-refile-tags' look like this

(defvar tn-refile-tags (list "tag:rfile" "tag:lst")
  "list of refile tag strings for use in a notmuch search")

Don't remember why I made this, really just using the rfile tag, but
anyway. Finally I have this binding:

(define-key notmuch-hello-mode-map (kbd "A") 'tn-refile-rfiles)

The effect is that offlineimap see those messages as deleted and sync
the deletion to the server. But for Notmuch the archive folder is a
valid folder and in my case it is "/home/tomas/Mail/archive/cur/".

Best regards
--
Tomas


More information about the notmuch mailing list