Module: Sisimai::Lhost::GoogleGroups
- Defined in:
- lib/sisimai/lhost/googlegroups.rb
Overview
Sisimai::Lhost::GoogleGroups decodes a bounce email which created by Google Groups groups.google.com. Methods in the module are called from only Sisimai::Message.
Constant Summary collapse
- Boundaries =
['----- Original message -----', 'Content-Type: message/rfc822'].freeze
Class Method Summary collapse
Class Method Details
.description ⇒ Object
71 |
# File 'lib/sisimai/lhost/googlegroups.rb', line 71 def description; return 'Google Groups: https://groups.google.com'; end |
.inquire(mhead, mbody) ⇒ Hash, Nil
This method is abstract.
Decodes the bounce message from Google Groups
15 16 17 18 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 62 63 64 65 66 67 68 69 70 |
# File 'lib/sisimai/lhost/googlegroups.rb', line 15 def inquire(mhead, mbody) return nil if mbody.include?("Google Group") == false return nil if mhead['from'].end_with?('<mailer-daemon@googlemail.com>') == false return nil if mhead['subject'].start_with?('Delivery Status Notification') == false return nil if mhead['x-failed-recipients'].nil? # Hello kijitora@libsisimai.org, # # We're writing to let you know that the group you tried to contact (group-name) # may not exist, or you may not have permission to post messages to the group. # A few more details on why you weren't able to post: # # * You might have spelled or formatted the group name incorrectly. # * The owner of the group may have removed this group. # * You may need to join the group before receiving permission to post. # * This group may not be open to posting. # # If you have questions related to this or any other Google Group, # visit the Help Center at https://groups.google.com/support/. # # Thanks, # # Google Groups dscontents = [Sisimai::Lhost.DELIVERYSTATUS]; v = dscontents[-1] emailparts = Sisimai::RFC5322.part(mbody, Boundaries) recipients = 0 # * You might have spelled or formatted the group name incorrectly. # * The owner of the group may have removed this group. # * You may need to join the group before receiving permission to post. # * This group may not be open to posting. entiremesg = emailparts[0].split(/\n\n/, 5).slice(0, 4).join(' ').tr("\n", ' '); receivedby = mhead['received'] || [] recordwide = { 'diagnosis' => entiremesg, 'reason' => 'onhold', 'rhost' => Sisimai::RFC5322.received(receivedby[0])[1], } recordwide['reason'] = 'rejected' if emailparts[0].scan(/^[ ]?[*][ ]?/).size == 4 mhead['x-failed-recipients'].split(',').each do |e| # X-Failed-Recipients: neko@example.jp, nyaan@example.org, ... next if Sisimai::Address.is_emailaddress(e) == false if v["recipient"] != "" # There are multiple recipient addresses in the message body. dscontents << Sisimai::Lhost.DELIVERYSTATUS v = dscontents[-1] end v['recipient'] = Sisimai::Address.s3s4(e) recipients += 1 recordwide.each_key { |r| v[r] = recordwide[r] } end return nil if recipients == 0 return { 'ds' => dscontents, 'rfc822' => emailparts[1] } end |