Commits

Anonymous committed 075a272

Option --list-folders and proper examples for gmail

  • Participants
  • Parent commits 848b4ef

Comments (0)

Files changed (1)

gmail_extract_emails.pl

            --csv=gmail.csv \
            --folder=INBOX
 
+In case you are not sure about folder names, try:
+
+    ./gmail_extract_emails.pl \
+           --username=[user] --password=[password] \
+           --list-folders
+
+first.
+
 Required parameters:
 
     --login         GMail username (either "SomeBody@gmail.com", or "SomeBody")
     --host          IMAP hostname  (default imap.gmail.com)
     --port          IMAP port      (default 993)
     --verbose       Print some diagnostic messages
+    --list-folders  Instead of running normally, list IMAP folders on the server
+                    (use if you are not sure what to give as --folder)
 
-Note that using --folder=Sent grabs addresses you sent email to.
+Note that using --folder='[Gmail]/Sent Mail' grabs addresses you sent email to
+and --folder='[Gmail]/All Mail' processes archived email.
 
 Options --host and --port can be useful if you use port mapping or tunelling, or
 just want to use IMAP server different than GMail.
 with 'MooseX::Getopt';
 
 has 'folder'  => (is => 'ro', isa => 'Str', default => "INBOX",
-                  documentation => "GMail folder to scan (by default INBOX, use Sent to check out messages)");
+                  documentation => "GMail folder to scan (by default INBOX, use --list-folders to check which folders are available)");
 has 'csv' => (is => 'ro', isa => 'Str', predicate => 'has_csv',
               documentation => "Name of created .csv file. Printing to stdout if not set");
 has 'host'  => (is => 'ro', isa => 'Str', default => "imap.gmail.com",
 has 'port'  => (is => 'ro', isa => 'Int', default => 993,
                 documentation => "GMail IMAP port (default 993, change if you are using some port mapping or tunelling)");
 has 'verbose' => (is => 'rw', isa => 'Bool', default => 0);
+has 'list-folders' => (is => 'rw', isa => 'Bool', default => 0, accessor => 'list_folders');
 has 'login'   => (is => 'rw', isa => 'Str', required => 1,
                   documentation => "GMail username (either \"SomeBody\@gmail.com\", or \"SomeBody\")");
 has 'password' => (is => 'rw', isa => 'Str', required => 1,
 sub run {
     my $self = shift;
 
+    if($self->list_folders) {
+        my $folders = $self->_imap->folders or die "Can't read folders list: " . $self->_imap->LastError . "\n";
+        print "Known folders:\n    ", join("\n    ", @$folders), "\n";
+        exit(0);
+    }
+
     # Uniquifying emails. email -> label -> count
     my %emails;