atrent
atrent

Reputation: 135

IMAP folders diff?

I'd like to "diff" two IMAP folders (on two different servers) to compare spam filters, I'd like to have a command line tool (linux) to get just the headers (not the whole dir, e.g. using 'isync' or similar), something like this:

$ imapget --subjects -p=password user@server

or this:

$ imapget --format "$DATE - $FROM - $SUBJ" -p=password user@server

('imapget' cmd is fictional)

What would you suggest?

Thank you

Upvotes: 1

Views: 1759

Answers (2)

ptman
ptman

Reputation: 917

I would mirror the two IMAP folders to local Maildir folders using something like OfflineIMAP, imapsync, imapcopy, isync or mailsync.

Then I'd use something like mailutils to output lists of messages in both and diff them.

Upvotes: 1

ADEpt
ADEpt

Reputation: 5542

The easies way is probably to get perl and Mail::IMAPClient and use something like:

     use Mail::IMAPClient;
     my $imap = Mail::IMAPClient->new(
         Server => $imaphost, User => $login, Password => $pass, Uid => 1
     );

     $imap->select("demo_folder");

     my $msgs = $imap->search("ALL");
     for my $h (

      # get specified headers from every message in folder "demo_folder" the

       values %{ $imap->parse_headers( $msgs , "Date", "From", "Subject") } )
     {
         # $h is the value of each element in the hash ref returned
         # from parse_headers, and $h is also a reference to a hash.
         # We'll only print the first occurrence of each field because
         # we don't expect more than one particular header line per
         # message.
         print map { "$_:\t$h->{$_}[0]\n"} keys %$h;
     }

Upvotes: 0

Related Questions