Class: IMAPToRSS::Handler::HSBC
- Inherits:
-
IMAPToRSS::Handler
- Object
- IMAPToRSS::Handler
- IMAPToRSS::Handler::HSBC
- Defined in:
- lib/imap_to_rss/handler/hsbc.rb
Overview
Handles messages from HSBC savings and HSBC credit cards
Instance Attribute Summary
Attributes inherited from IMAPToRSS::Handler
Instance Method Summary collapse
-
#handle(uids) ⇒ Object
Turns
uids
into RSS items for bank-to-bank transfers and general announcements like CC payments due or interest rate changes. -
#initialize ⇒ HSBC
constructor
Selects messages with hsbc in the From header.
Methods inherited from IMAPToRSS::Handler
#add_item, #each_message, handlers, inherited, #log, #setup
Constructor Details
#initialize ⇒ HSBC
Selects messages with hsbc in the From header
11 12 13 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 11 def initialize @search = 'FROM', 'hsbc' end |
Instance Method Details
#handle(uids) ⇒ Object
Turns uids
into RSS items for bank-to-bank transfers and general announcements like CC payments due or interest rate changes.
19 20 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 |
# File 'lib/imap_to_rss/handler/hsbc.rb', line 19 def handle(uids) uids, 'text/plain' do |uid, mail| url = nil description = nil case mail.from.first when '[email protected]' then mail.body =~ /^Dear.*?, ([ \t]*\r?\n){2,} (.*?) ([ \t]*\r?\n){2,}/mx next false unless $2 description = $2 when '[email protected]' then mail.body =~ /^Dear.*?[,:] ([ \t]*\r?\n){2,} (.*?) ([ \t]*\r?\n){2,} Sincerely,/mx next false unless $2 body = $2 body.gsub!(/[*\r]/, '') body.gsub!(/[ \t]*\n/, "\n") body = body.split(/\n\n+/).map { |para| "<p>#{para}</p>" } description = body.join "\n\n" when '[email protected]' then mail.body =~ /^(http:.*)/ next false unless $1 url = $1 else log "Unknown From: #{mail.from.join ', '}" next false end add_item mail.subject, description, mail.from, mail.date, url, mail., 'HSBC' end end |