Module: GmailExtractor
- Defined in:
- lib/gmail_extractor.rb,
lib/gmail_extractor/email.rb,
lib/gmail_extractor/version.rb,
lib/gmail_extractor/email_extractor.rb,
lib/gmail_extractor/email_progressbar.rb,
lib/gmail_extractor/printer/file_printer.rb,
lib/gmail_extractor/printer/console_printer.rb,
lib/gmail_extractor/email_formatter/email_csv_formatter.rb,
lib/gmail_extractor/email_formatter/email_xml_formatter.rb,
lib/gmail_extractor/email_formatter/email_html_formatter.rb
Defined Under Namespace
Classes: ConsolePrinter, Email, EmailCsvFormatter, EmailExtractor, EmailHtmlFormatter, EmailProgressbar, EmailXmlFormatter, FilePrinter
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gmail_extractor.rb', line 21 def self.execute # Reading from command line require "optparse" = {} OptionParser.new do |opts| opts. = "Usage: get_mails.rb [options]" opts.on("-u","--username USERNAME","Set gmail USERNAME") do |username| [:username] = username end opts.on("-p","--password PASSWORD","Set gmail PASSWORD") do |password| [:password] = password end opts.on("-n","--name NAME","Set own NAME; defaults to Self if not given") do |name| [:name] = name || "Self" end opts.on("-m","--mailbox MAILBOX","Set MAILBOX from where the mails are fetched. Label names can be used too!") do |mailbox| [:mailbox] = mailbox end opts.on("-l","--limit LIMIT","Set limit LIMIT to how many emails are fetched; defaults to all if not given") do |limit| [:limit] = limit.to_i end opts.on("-o","--output TYPE","Set output TYPE to xml, csv or html. defaults to csv") do |output| [:output] = output || "csv" end opts.on("-f","--file FILE","Set output FILE. if not present, only output to STDOUT") do |file| [:file] = file end opts.on("-pb","--progressbar","Show progressbar on STDOUT") do [:progressbar] = true end opts.on("-h", "--help", "Show this message") do puts opts exit end end.parse! # set printer file = [:file] if file printer = ConsolePrinter.new(FilePrinter.new(file)) else printer = ConsolePrinter.new end # set correct formatter if [:output] output = [:output].downcase else output = "csv" end if output == "xml" formatter = EmailXmlFormatter.new(printer) elsif output == "csv" formatter = EmailCsvFormatter.new(printer) elsif output == "html" formatter = EmailHtmlFormatter.new(printer) else raise "Internal error - no output option given" end # handle progressbar if [:progressbar] formatter = EmailProgressbar.new(formatter) end # Asking missing values require "highline/import" user = [:username] || ask("Enter user: ") password = [:password] || ask("Enter password: ") { |q| q.echo = false } name = [:name] extractor = EmailExtractor.new(user,password,name,formatter) # Ask missing values and extract label = [:mailbox] || ask("Enter mailbox/label: ") limit = [:limit] extractor.extract(label, limit) end |