def run(data)
username = config['username']
password = config['password']
server = config['imap_server'] || 'imap.gmail.com'
port = config['port'] || 993
usessl = ('off' != config['ssl'])
mailbox = config['mailbox'] || 'inbox'
wait = config['wait'] || 1
unless config['mail']
config['mail'] = {}
end
subject_prefix = config['mail']['subject_prefix'] || ''
from = config['mail']['from'] || 'yapra@localhost'
to = config['mail']['to'] || 'me@localhost'
imap = create_imap server, port, usessl
logger.debug(imap.greeting)
imap.login(username, password)
logger.info('imap login was succeed.')
imap.examine(mailbox)
data.each do |item|
date = item.date || item.dc_date || Time.now
content = item.content_encoded || item.description || 'from Yapra.'
content = [content].pack('m')
if config['mail']['from_template']
from = apply_template(config['mail']['from_template'], binding)
end
if config['mail']['to_template']
to = apply_template(config['mail']['to_template'], binding)
end
subject = (subject_prefix + item.title).gsub(/\n/, '').chomp
logger.debug("try append item: #{subject}")
boundary = "----_____====#{Time.now.to_i}--BOUDARY"
attachments = create_attachments(item, config)
imap.append(mailbox, apply_template(mail_template, binding), nil, date)
sleep wait
end
imap.disconnect
data
end