# module: Publish::Imap -- Yuanying # # publish entry to imap mail. # # example: # # - module: Publish::Imap # config: # username: username # password: password # imap_server: imap.gmail.com # port: 993 # ssl: on # wait: 1 # mail: # subject_prefix: '[Yapra]' # from: 'test@example.com' # to: 'test2@example.com' # require 'net/imap' require 'yapra/plugin/base' module Yapra::Plugin::Publish class Imap < Yapra::Plugin::Base 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.info(imap.greeting) imap.login(username, password) 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') imap.append("inbox", <