Re: Sync mail deletion with Notmuch + mbsync for gmail

2016-09-21 Thread Sebastian Fischmeister
Thanks. I'll try this, because it looks simpler than what I have. Here's
what's working so far:

Note: Gmail has a proprietary implementation of IMAP. To delete an
email, you first must move the email to the trash folder on the
server. You can find this info through archive.org, because Google now
redirects the page where they originally explained this.

https://web.archive.org/web/20151013132129/https://support.google.com/mail/answer/78755

Concept:

- Deleting emails adds the +delete tag.
- Archiving emails add the +processed tag.

- Before syncing emails, process archived messages by copying them to
  the archive folder and moving them to the trash folder. Moving is more
  elaborate, because you have to remove the UID for mbsync

notmuch search --output=files tag:processed and folder:inbox | grep -v archived 
| xargs -I{} cp -f {} ~/.mail/archived/cur/
notmuch search --output=files tag:processed and folder:sent | grep -v archived 
| xargs -I{} cp -f {} ~/.mail/archived/cur/

function moveIt { s=${1##*/}; s=${s%%,*}; mv -f $1 $2/$s
s=$(notmuch search --output=files tag:processed and folder:sent | grep -v 
archived)
for i in $s; do moveIt $i /home/sfischme/.mail/totrash/new; done
}

- Before syncing, move deleted messages to the trash

s=$(notmuch search --output=files tag:delete and not folder:totrash | grep -v 
archived)
for i in $s; do moveIt $i /home/sfischme/.mail/totrash/new; done

- Invoke mbsync

Caveats:

- You need more bandwidth as you copy emails back to the server just to
  delete them.

- Make sure your scripts work, otherwise things get out of sync.


  Sebastian


"aaermo...@gmail.com"  writes:

>  Hi Sebastian,
>
>  I also use mbsync + notmuch
>
>  here is mbsync config for my personal Gmail mailbox:
>  =
>  SyncState *
>
>  IMAPAccount aaermo...@gmail.com
>  Host imap.gmail.com
>  User aaermo...@gmail.com
>  PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d 
> ~/docs/enc/cred/aaermo...@gmail.com.gpg"
>  CertificateFile /etc/ssl/certs/ca-certificates.crt
>  SSLType IMAPS
>
>  IMAPStore aaermo...@gmail.com-remote
>  Account aaermo...@gmail.com
>
>  MaildirStore aaermo...@gmail.com-local
>  Path ~/Maildir/aaermo...@gmail.com/
>  Inbox ~/Maildir/aaermo...@gmail.com/INBOX
>  SubFolders Verbatim
>
>  MaildirStore aaermo...@gmail.com-archive
>  Path ~/Maildir/archive-aaermo...@gmail.com/
>
>  Channel aaermo...@gmail.com-archive
>  Master ":aaermo...@gmail.com-remote:[Gmail]/All Mail"
>  Slave ":aaermo...@gmail.com-archive:Archive"
>  Create Slave
>  SyncState *
>  Sync Push Flags
>
>  Channel aaermo...@gmail.com-trash
>  Master ":aaermo...@gmail.com-remote:[Gmail]/Trash"
>  Slave ":aaermo...@gmail.com-archive:Trash"
>  Create Slave
>  Sync All
>
>  Channel aaermo...@gmail.com-drafts
>  Master ":aaermo...@gmail.com-remote:[Gmail]/Drafts"
>  Slave ":aaermo...@gmail.com-local:Drafts"
>  Create Slave
>  Sync All
>  Expunge Both
>
>  Channel aaermo...@gmail.com-sent
>  Master ":aaermo...@gmail.com-remote:[Gmail]/Sent Mail"
>  Slave ":aaermo...@gmail.com-local:Sent"
>  Create Slave
>  Sync All
>  Expunge Both
>
>  Channel aaermo...@gmail.com-inbox
>  Master ":aaermo...@gmail.com-remote:INBOX"
>  Slave ":aaermo...@gmail.com-local:INBOX"
>  Create Slave
>  Sync All
>  Expunge Both
>
>  Channel aaermo...@gmail.com-user-labels
>  Master :aaermo...@gmail.com-remote:
>  Slave :aaermo...@gmail.com-local:
>  Create Slave
>  Sync All
>  Patterns "*" "!Drafts" "!Sent" "!Trash" "![Gmail]*" "!INBOX" "!Lists*" 
> "!Cron*"
>  Expunge Both
>
>  Channel aaermo...@gmail.com-mailing-lists-and-notifications
>  Master :aaermo...@gmail.com-remote:
>  Slave :aaermo...@gmail.com-local:
>  Create Slave
>  Sync All
>  Patterns "Lists*" "Cron*"
>  # MaxMessages 2000
>  Expunge Both
>
>  Group aaermo...@gmail.com
>  Channel aaermo...@gmail.com-trash
>  Channel aaermo...@gmail.com-inbox
>  Channel aaermo...@gmail.com-drafts
>  Channel aaermo...@gmail.com-sent
>  Channel aaermo...@gmail.com-user-labels
>  Channel aaermo...@gmail.com-mailing-lists-and-notifications
>  Channel aaermo...@gmail.com-archive
>  =
>
>  But I also use imapfilter for trashed and spam messages management, so
>  when I delete something locally, AFAIK it correctly propagates to Gmail.
>
>  Here is imapfilter's config:
>  =
>  options.timeout = 120
>  options.subscribe = true
>
>  cmd_personal = io.popen('gpg2 -q --for-your-eyes-only --no-tty -d 
> ~/docs/enc/cred/aaermo...@gmail.com.gpg', 'r')
>  out_personal = cmd_personal:read('*a')
>  pass_personal = string.gsub(out_personal, '[\n\r]+', '')
>
>  account_personal = IMAP {
>   server = 'imap.gmail.com',
>   username = 'aaermo...@gmail.com',
>   password = pass_personal,
>   ssl = 'ssl3'
>   }
>
>  trash_personal = account_personal['[Gmail]/Trash']:is_undeleted()
>  account_personal['[Gmail]/Trash']:delete_messages(trash_personal)
>

Re: Sync mail deletion with Notmuch + mbsync for gmail

2016-09-21 Thread aaermolov
 Hi Sebastian,

 I also use mbsync + notmuch

 here is mbsync config for my personal Gmail mailbox:
 =
 SyncState *

 IMAPAccount aaermo...@gmail.com
 Host imap.gmail.com
 User aaermo...@gmail.com
 PassCmd "gpg2 -q --for-your-eyes-only --no-tty -d 
~/docs/enc/cred/aaermo...@gmail.com.gpg"
 CertificateFile /etc/ssl/certs/ca-certificates.crt
 SSLType IMAPS

 IMAPStore aaermo...@gmail.com-remote
 Account aaermo...@gmail.com

 MaildirStore aaermo...@gmail.com-local
 Path ~/Maildir/aaermo...@gmail.com/
 Inbox ~/Maildir/aaermo...@gmail.com/INBOX
 SubFolders Verbatim

 MaildirStore aaermo...@gmail.com-archive
 Path ~/Maildir/archive-aaermo...@gmail.com/

 Channel aaermo...@gmail.com-archive
 Master ":aaermo...@gmail.com-remote:[Gmail]/All Mail"
 Slave ":aaermo...@gmail.com-archive:Archive"
 Create Slave
 SyncState *
 Sync Push Flags

 Channel aaermo...@gmail.com-trash
 Master ":aaermo...@gmail.com-remote:[Gmail]/Trash"
 Slave ":aaermo...@gmail.com-archive:Trash"
 Create Slave
 Sync All

 Channel aaermo...@gmail.com-drafts
 Master ":aaermo...@gmail.com-remote:[Gmail]/Drafts"
 Slave ":aaermo...@gmail.com-local:Drafts"
 Create Slave
 Sync All
 Expunge Both

 Channel aaermo...@gmail.com-sent
 Master ":aaermo...@gmail.com-remote:[Gmail]/Sent Mail"
 Slave ":aaermo...@gmail.com-local:Sent"
 Create Slave
 Sync All
 Expunge Both

 Channel aaermo...@gmail.com-inbox
 Master ":aaermo...@gmail.com-remote:INBOX"
 Slave ":aaermo...@gmail.com-local:INBOX"
 Create Slave
 Sync All
 Expunge Both

 Channel aaermo...@gmail.com-user-labels
 Master :aaermo...@gmail.com-remote:
 Slave :aaermo...@gmail.com-local:
 Create Slave
 Sync All
 Patterns "*" "!Drafts" "!Sent" "!Trash" "![Gmail]*" "!INBOX" "!Lists*" "!Cron*"
 Expunge Both

 Channel aaermo...@gmail.com-mailing-lists-and-notifications
 Master :aaermo...@gmail.com-remote:
 Slave :aaermo...@gmail.com-local:
 Create Slave
 Sync All
 Patterns "Lists*" "Cron*"
 # MaxMessages 2000
 Expunge Both

 Group aaermo...@gmail.com
 Channel aaermo...@gmail.com-trash
 Channel aaermo...@gmail.com-inbox
 Channel aaermo...@gmail.com-drafts
 Channel aaermo...@gmail.com-sent
 Channel aaermo...@gmail.com-user-labels
 Channel aaermo...@gmail.com-mailing-lists-and-notifications
 Channel aaermo...@gmail.com-archive
 =

 But I also use imapfilter for trashed and spam messages management, so
 when I delete something locally, AFAIK it correctly propagates to Gmail.

 Here is imapfilter's config:
 =
 options.timeout = 120
 options.subscribe = true

 cmd_personal = io.popen('gpg2 -q --for-your-eyes-only --no-tty -d 
~/docs/enc/cred/aaermo...@gmail.com.gpg', 'r')
 out_personal = cmd_personal:read('*a')
 pass_personal = string.gsub(out_personal, '[\n\r]+', '')

 account_personal = IMAP {
  server = 'imap.gmail.com',
  username = 'aaermo...@gmail.com',
  password = pass_personal,
  ssl = 'ssl3'
  }

 trash_personal = account_personal['[Gmail]/Trash']:is_undeleted()
 account_personal['[Gmail]/Trash']:delete_messages(trash_personal)

 spam_personal = account_personal['[Gmail]/Spam']:is_unanswered()
 account_personal['[Gmail]/Spam']:delete_messages(spam_personal)
 =

 Cheers, Alex

PS Sorry for double posting, have forgot all recepients the first time.

Sebastian Fischmeister  writes:

> Hi,
>
> I use mbsync + notmuch to sync my gmail. The problem is that Google's
> IMAP implementation is non-standard and when I deleted a file locally,
> mbsync propagates the deletion, but gmail doesn't delete the
> message. 
>
> This is part of mbsync:
>
> SyncState *
> Sync All
> Expunge Both
> Create Both
>
> When I delete a message, the macro passes the tag 'delete'. Before
> syncing, the script runs:
>
> notmuch search --output=files tag:delete | xargs -l rm
>
> By playing with the IMAP settings in gmail, I got it so that the mail
> vanishes from the 'inbox' label, but it's still in 'All Mails'. I also
> tried moving it to a "[GMail]/Trash" folder locally and syncing that,
> but it didn't work.
>
> Any ideas?
>
>   Sebastian
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Sync mail deletion with Notmuch + mbsync for gmail

2016-09-15 Thread Sebastian Fischmeister
Hi,

I use mbsync + notmuch to sync my gmail. The problem is that Google's
IMAP implementation is non-standard and when I deleted a file locally,
mbsync propagates the deletion, but gmail doesn't delete the
message. 

This is part of mbsync:

SyncState *
Sync All
Expunge Both
Create Both

When I delete a message, the macro passes the tag 'delete'. Before
syncing, the script runs:

notmuch search --output=files tag:delete | xargs -l rm

By playing with the IMAP settings in gmail, I got it so that the mail
vanishes from the 'inbox' label, but it's still in 'All Mails'. I also
tried moving it to a "[GMail]/Trash" folder locally and syncing that,
but it didn't work.

Any ideas?

  Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch