Skip to content

Instantly share code, notes, and snippets.

@ArseniyShestakov
Last active August 10, 2023 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ArseniyShestakov/46962f46d47301b6be341460964439b6 to your computer and use it in GitHub Desktop.
Save ArseniyShestakov/46962f46d47301b6be341460964439b6 to your computer and use it in GitHub Desktop.
Parse all emails from mail server without chaning state on server
# copy getmail config to ~/.getmail/getmailrc
# Create some temporary directories
mkdir -p /tmp/mail/cur
mkdir -p /tmp/mail/tmp
mkdir -p /tmp/mail/new
mkdir /tmp/mail/parsing
# Gather all emails
# They won't be removed from mail server and won't be marked as "read" on server since "peek" used
getmail
# Now move emails you want to different directory:
grep -L -Z -r 'user@needserverfrom.info' /tmp/mail/new | xargs -0 -I{} mv {} /tmp/mail/parsing
# Encoded and multipart emails can be decoded using little Python like:
https://stackoverflow.com/questions/33083849/how-to-extract-an-email-body-from-a-file-using-email-parser
[retriever]
type = SimpleIMAPSSLRetriever
server = imap.server.com
port = 993
mailboxes = ALL
username = use@server,com
password = Password123
[destination]
type = Maildir
path = /tmp/mail/
[options]
delete = false
read_all = true
use_peek = true
message_log = ~/.getmail/log-foreman-example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment