Skip to content

Instantly share code, notes, and snippets.

@callmeradical
Created November 6, 2013 18:53
Show Gist options
  • Save callmeradical/7341958 to your computer and use it in GitHub Desktop.
Save callmeradical/7341958 to your computer and use it in GitHub Desktop.
A ruby script to use with get mail for downloading all mall from a user.
require 'optparse'
options = {}
puts "This script is meant to be used with GoogleApps accounts."
OptionParser.new do |opts|
opts.banner = "Usage: rgetmail.rb [options]"
opts.on('-e', '--email EMAIL_ADDRESS','User Email Address') { |v| options[:email] = v }
opts.on('-n', '--name NAME_OF_USER','First name of the user') { |v| options[:name] = v }
opts.on('-p', '--password USER_PASSWORD', 'Password for Account') { |v| options[:pass] = v }
end.parse!
temp_file = "config.gmail"
config_file = [
"[retriever]",
"type = SimpleIMAPSSLRetriever",
"server = imap.gmail.com",
"username = #{options[:email]}",
"password = #{options[:pass]}",
"mailboxes = ('[Gmail]/All Mail',)",
"[destination]",
"type = Mboxrd",
"path = /Users/lcromley/Desktop/#{options[:name]}.mbox",
"[options]",
"verbose = 2",
]
Dir.chdir("/Users/lcromley/.getmail/")
if File.exist?("#{temp_file}")
`touch /Users/lcromley/.getmail/#{temp_file}`
`touch /Users/lcromley/Desktop/#{options[:name]}.mbox`
`touch /Users/lcromley/Desktop/gmail.log && chmod 777 /Users/lcromley/Desktop/gmail.log`
end
config_file.each do |f|
File.open("/Users/lcromley/.getmail/#{temp_file}", "a") do |line|
line.puts f
end
end
`getmail -qa -r /Users/lcromley/.getmail/#{temp_file}`
`rm /Users/lcromley/.getmail/#{temp_file}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment