class ImapFilter::Functionality::FunctFilter
Attributes
dfilt[RW]
Public Class Methods
new(filt)
click to toggle source
# File lib/imap-filter/functionality.rb, line 66 def initialize filt @dfilt = filt @seq = nil end
Public Instance Methods
_cross_account_mvcp(op, dest_acc, dest_mbox)
click to toggle source
# File lib/imap-filter/functionality.rb, line 119 def _cross_account_mvcp op, dest_acc, dest_mbox ensure_mailbox dest_acc, dest_mbox begin acc.imap.fetch(seq, FULL).each do |fdat| unless _options[:verbose] < 2 print " >>".yellow puts " seq #{fdat.seqno} #{fdat.attr['ENVELOPE']['subject']} -> #{dest_acc.name}:#{dest_mbox}".light_blue end raw = fdat.attr['ENVELOPE'].email_header + fdat.attr[BODYTEXT] dest_acc.imap.append dest_mbox, raw, fdat.attr['FLAGS'] acc.imap.noop # just to keep this account open TODO: we do not need a noop on every iteration end rescue => e puts "ERROR: #{e} -- perhaps you did a move or delete operation before copy?".light_red exit 10 end end
_mvcp(op, destination)
click to toggle source
# File lib/imap-filter/functionality.rb, line 137 def _mvcp op, destination raise "Illegal operation #{op}" unless [:copy, :move].member? op dest_acc, dest_mbox = parse_and_resolve_account_mbox_string destination ensure_mailbox dest_acc, dest_mbox if dest_acc == acc # in-account move dest_acc.imap.send op, seq, dest_mbox else # move or copy to different account _cross_account_mvcp op, dest_acc, dest_mbox end unless seq.empty? end
copy(destination)
click to toggle source
# File lib/imap-filter/functionality.rb, line 155 def copy destination puts " copy from #{acc.name} to #{destination}".light_blue unless _options[:verbose] < 1 _mvcp :copy, destination unless _options[:dryrun] end
delete()
click to toggle source
# File lib/imap-filter/functionality.rb, line 160 def delete puts " delete from #{acc.name}".light_blue unless _options[:verbose] < 1 mark :Deleted unless _options[:dryrun] end
ensure_mailbox(account, mailbox)
click to toggle source
# File lib/imap-filter/functionality.rb, line 89 def ensure_mailbox account, mailbox begin account.ensure_mailbox mailbox rescue Net::IMAP::NoResponseError => e puts " *** ignored mailbox error: #{e}".red unless _options[:verbose] < 1 end end
list(*a, **h)
click to toggle source
# File lib/imap-filter/functionality.rb, line 113 def list *a, **h subject_list.each do |subject| puts subject.attr[subj].to_s.strip.tr("\n\r", '').light_yellow end unless seq.empty? end
mark(*flags)
click to toggle source
# File lib/imap-filter/functionality.rb, line 165 def mark *flags puts " mark #{flags} in #{acc.name}".light_blue unless _options[:verbose] < 1 puts "DISCONNECTED".light_red if acc.imap.disconnected? acc.imap.store seq, '+FLAGS.SILENT', flags unless seq.empty? or _options[:dryrun] end
move(destination)
click to toggle source
# File lib/imap-filter/functionality.rb, line 150 def move destination puts " move from #{acc.name} to #{destination}".light_blue unless _options[:verbose] < 1 _mvcp :move, destination unless _options[:dryrun] end
parse_and_resolve_account_mbox_string(ambox, default_account = nil)
click to toggle source
These strings come from the DSL
in the form of “acct:mbox_path”. Reslove and return the actual account object and mbox path as [account_ob, mbox]
# File lib/imap-filter/functionality.rb, line 74 def parse_and_resolve_account_mbox_string ambox, default_account = nil a, b = ambox.split ':' a, b = [nil, a] if b.nil? a = nil if a == '' acc = Functionality::_functional_accounts[ a.nil? ? default_account : a.to_sym ] mbox = b [acc, mbox] end
process_actions()
click to toggle source
# File lib/imap-filter/functionality.rb, line 97 def process_actions actions.each do |action| send *action end end
select_email()
click to toggle source
# File lib/imap-filter/functionality.rb, line 83 def select_email @acc, box = parse_and_resolve_account_mbox_string mbox acc.imap.select box @seq = acc.imap.search directives end
subject_list()
click to toggle source
# File lib/imap-filter/functionality.rb, line 103 def subject_list unless seq.empty? acc.imap.fetch(seq, SUBJECTPEEKLIST).map do |subject| subject.attr[SUBJECTLIST].to_s.strip.tr("\n\r", '') end else [] end end
unmark(*flags)
click to toggle source
# File lib/imap-filter/functionality.rb, line 171 def unmark *flags puts " unmark #{flags} in #{acc.name}".light_blue unless _options[:verbose] < 1 acc.imap.store seq, '-FLAGS.SILENT', flags unless seq.empty? or _options[:dryrun] end