Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable "sent" folder name and dynamic contacts export #169

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions lib/vmail/contacts_extractor.rb
Expand Up @@ -2,13 +2,20 @@

module Vmail
class ContactsExtractor
def initialize(username, password)
puts "Logging as #{username}"
@username, @password = username, password

def initialize(config)
@host = config['server'] || 'imap.gmail.com'
@port = config['port'] || 993
@sent_folder = config['folder_sent'] || 'Sent Mail'
@username = config['username']
@password = config['password']
@server = config['server']
@prefix = ''
puts "Logging as #@username at #@host scanning the \"#@sent_folder\" folder"
end

def open
@imap = Net::IMAP.new('imap.gmail.com', 993, true, nil, false)
@imap = Net::IMAP.new(@host, @port, true, nil, false)
puts @imap.login(@username, @password)
yield @imap
@imap.close
Expand All @@ -18,7 +25,7 @@ def open
def extract(limit = 500)
open do |imap|
set_mailbox_prefix
mailbox = "[#@prefix]/Sent Mail"
mailbox = "#@prefix#@sent_folder"
STDERR.puts "Selecting #{mailbox}"
imap.select(mailbox)
STDERR.puts "Fetching last #{limit} sent messages"
Expand Down Expand Up @@ -46,7 +53,9 @@ def extract(limit = 500)

def set_mailbox_prefix
mailboxes = ((@imap.list("[#@prefix]/", "%") || []) + (@imap.list("", "*")) || []).map {|struct| struct.name}
@prefix = mailboxes.detect {|m| m =~ /^\[Google Mail\]/} ? "Google Mail" : "Gmail"
if !@server
@prefix = mailboxes.detect {|m| m =~ /^\[Google Mail\]/} ? "[Google Mail]/" : "[Gmail]/"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vmail/options.rb
Expand Up @@ -73,7 +73,7 @@ def parse(argv)

if @get_contacts
require 'vmail/contacts_extractor'
extractor = ContactsExtractor.new(@config['username'], @config['password'])
extractor = ContactsExtractor.new(@config)
File.open(DEFAULT_CONTACTS_FILENAME, 'w') do |file|
extractor.extract(@max_messages_to_scan) do |address|
STDERR.print '.'
Expand Down
2 changes: 1 addition & 1 deletion lib/vmail/version.rb
@@ -1,3 +1,3 @@
module Vmail
VERSION = '2.8.7'
VERSION = '2.8.8'
end