6 # Copies mail from a gmail account
7 # You need ruby 1.9 for this
8 # You need the password gem for this
10 # Problem: this appears to only download some mails (usually around 383 or
11 # so). One workaround is to run this multiple times. Still not sure if there
12 # is a better workaround.
26 # Fill in $opts values
27 parser = OptionParser.new do |myparser|
28 myparser.banner = "Usage: #{ File.basename($0) } [opts]"
29 myparser.separator("Specific options:")
30 myparser.on("--username USERNAME", "-u",
31 "Email account to fetch. (example: \
32 RareCactus@gmail.com)") do |u|
35 myparser.on("--dry-run", "-d",
36 "Dry run. State what would be done without actually \
43 raise "must give a username" unless opts.username
50 $opts = MyOptions.parse(ARGV)
51 rescue Exception => msg
52 $stderr.print("#{msg}.\nType --help to see usage information.\n")
56 puts "type password for #{$opts.username}"
60 Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
61 Net::POP3.start("pop.gmail.com", 995, $opts.username, password) do |pop|
65 puts "found #{n_mails} mails."
67 puts "successfully connected."
72 fname = mail.unique_id
73 #fname = sprintf("%08d", count)
74 File.open(fname, 'w+') do|f|
78 if ((count % 100) == 0)