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