Petrea Corneliu Ştefan > Mail-Google-Procmailrc-0.022 > Mail::Google::Procmailrc



Annotate this POD


Open  1
View/Report Bugs
Module Version: 0.022   Source  


Mail::Google::Procmailrc - Perl module that allows easy conversion from Gmail mail filters to Procmail rules


  use Mail::Google::Procmailrc;
  my $o = Mail::Google::Procmailrc->new(<path-to-mail-folders>);
  $o->convert(<google-mail-filter-path>, <procmail-rules-output-path>);

or, you can use it with the helper script

  google-to-procmailrc --input ./mailFilters.xml --output test-procmail.rc --mdir-path $HOME/somemail


You may want at some point, for some reason to export all your gmail mail rules as procmail filters.

If you use a mail setup involving OfflineIMAP fetching multiple folders(labels) from Google, you'll notice that there is a certain overhead involved.

That's because OfflineIMAP needs to tell the IMAP server, which messages it has, in order to retrieve only the ones that it doesn't, and then for each new message fetched it also needs to update the SQLite local dbs with the statuses of the new messages. And it has to do that for every folder(label). That highly depends on which labels you fetch with OfflineIMAP.

If you want to make the sync faster, you can consider only fetching the "[Gmail]/All Mail" folder or the "INBOX" folder, but then you still have to solve mail triage.

Procmail is quite good for mail triage, but the mailFilters.xml file that you can export from Gmail is not suited for use with Procmail AFAIK.

This module aims to solve that problem by converting mailFilters.xml to a set of procmail rules (effectively a procmailrc file).

Normally, you'd use the script that comes with this module to migrate your Gmail rules to procmail and then you can just maintain the procmail rules. At least that's how I(plan to) use it.


new($folders_path, $archive_dir, $trash_dir)

The constructor receives $folders_path which is the directory where all the mail folders resulting from the triage will be placed. The other two, archive and trash will be used with the same role as archiving e-mail, and the [Gmail]/Trash folder.


This method will generate a script called . This script will create all the folders. Afterwards, there will be a one-to-one mapping between the labels present in your mailFilters.xml and folders on disk. They will be empty, but after running procmail they will be filled with the mails that correspond to them.


Returns a catchall rule for the inbox


This method takes the input XML and uses "adapt" to convert it to the procmail rules file.


Receives as parameter a nested hash structure generated by XML::Fast from parsing the mailFilters.xml file, then traverses that structure. This is where the conversion happens.


Collects labels found so that can be generated. See the "generate_create_dirs_script" method for details.


Generates appropriate flag if the rule chain has not ended yet.


Generic "From:" rule conversion.


Adds a X-Procmail-Debug header to the e-mail so you can trace back to the rule that matched it.

This is triggered through the --debug parameter.


Generic "To:" rule conversion.


Uses the "rule_to" , "rule_from", "rule_subject", "rule_body" methods to archive e-mail.


Same as rule_archive but for trash.


Checks if there are multiple locations where the mail should be placed. Stores whether there are multiple such places and how many of them are. This will later be used in order to


Escape the field values used for the procmail filters


Converts a Gmail mail filter to procmail rules. Returns a string with the procmail rule.


If you decide to use [Gmail]/All Mail as the folder you sync and then use procmail to run on it, you'll have to deal with the Spam (maybe spamassassin would help there).

From that point of view it's probably easier to just use INBOX.

Currently this module only has functionality for converting some of the gmail rules.



Please report bugs using the queue.


Patches are welcome, either in the form of pull-requests on the github repo or in the form of patches on cpan's request tracker


Stefan Petrea, <>


Copyright (C) 2014 by Stefan Petrea

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: