Class: MailDiode::MaildirMessageHandler
- Inherits:
-
MailHandler
- Object
- MailHandler
- MailDiode::MaildirMessageHandler
- Defined in:
- lib/maildir.rb
Instance Method Summary collapse
- #get_maildir(recipient) ⇒ Object
-
#initialize(settings) ⇒ MaildirMessageHandler
constructor
A new instance of MaildirMessageHandler.
-
#load_settings(settings) ⇒ Object
def valid_recipient?(recipient) if (get_maildir(recipient)) return true end # @core.log.debug “Rejecting recipient: #recipient” return false end def deliver_message(recipient, envelope_to, folder, raw_message_object) received = “Received: from #raw_message_objectraw_message_object.heloname ” + “(#raw_message_objectraw_message_object.origin_ip) ” + “by #raw_message_objectraw_message_object.myhostname ” + “with SMTP ID #raw_message_objectraw_message_object.smtp_id ” + “for <#recipient>; ” + #“#raw_message_objectraw_message_object.timestampraw_message_object.timestamp.to_sn” “#Time.now.to_sn” full_text = received + raw_message_object.content.gsub(“r”,“”) message = DeliverableMessage.new(full_text) dir = “#get_maildir(recipient)get_maildir(recipient).chomp(‘/’)#folder/” # @core.log.info “Delivering for #envelope_to to #dir” if !File.exist?(dir) # @core.log.error “ERROR: Missing maildir folder: #dir” raise FolderMissingError.new(File.basename(dir)) end message.save(dir) return true end.
- #process_message(original_recipient, recipient, full_text) ⇒ Object
- #valid_recipient?(recipient) ⇒ Boolean
Constructor Details
#initialize(settings) ⇒ MaildirMessageHandler
Returns a new instance of MaildirMessageHandler.
44 45 46 47 |
# File 'lib/maildir.rb', line 44 def initialize(settings) @maildirs = {} load_settings(settings) end |
Instance Method Details
#get_maildir(recipient) ⇒ Object
66 67 68 |
# File 'lib/maildir.rb', line 66 def get_maildir(recipient) return @maildirs[recipient] end |
#load_settings(settings) ⇒ Object
def valid_recipient?(recipient) if (get_maildir(recipient)) return true end # @core.log.debug “Rejecting recipient: #recipient” return false end def deliver_message(recipient, envelope_to, folder, raw_message_object) received = “Received: from #MailDiode::MaildirMessageHandler.raw_message_objectraw_message_object.heloname ” + “(#MailDiode::MaildirMessageHandler.raw_message_objectraw_message_object.origin_ip) ” + “by #MailDiode::MaildirMessageHandler.raw_message_objectraw_message_object.myhostname ” + “with SMTP ID #MailDiode::MaildirMessageHandler.raw_message_objectraw_message_object.smtp_id ” + “for <#recipient>; ” + #“#MailDiode::MaildirMessageHandler.raw_message_objectraw_message_object.timestampraw_message_object.timestamp.to_sn” “#Time.now.to_sn” full_text = received + raw_message_object.content.gsub(“r”,“”) message = DeliverableMessage.new(full_text) dir = “#MailDiode::MaildirMessageHandler.get_maildir(recipient)get_maildir(recipient).chomp(‘/’)#folder/” # @core.log.info “Delivering for #envelope_to to #dir” if !File.exist?(dir) # @core.log.error “ERROR: Missing maildir folder: #dir” raise FolderMissingError.new(File.basename(dir)) end message.save(dir) return true end
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/maildir.rb', line 101 def load_settings(settings) settings.get_settings('maildir').each do | setting | name = setting.key maildir = setting.value if(maildir.index('/') != 0) raise "Maildir must start with slash (/): #{maildir}" end maildir.untaint @maildirs[name] = maildir #Disabled because this is called per-connection #MailDiode::log_debug " #{name} -> #{maildir}" end end |
#process_message(original_recipient, recipient, full_text) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/maildir.rb', line 53 def (original_recipient, recipient, full_text) = DeliverableMessage.new(full_text) raw_dir = get_maildir(recipient) folder = '' dir = "#{raw_dir.chomp('/')}#{folder}/" MailDiode::log_info "Delivering to #{dir} for #{original_recipient}" if !File.exist?(dir) MailDiode::log_error "ERROR: Missing maildir folder: #{dir}" raise FolderMissingError.new(File.basename(dir)) end .save(dir) end |
#valid_recipient?(recipient) ⇒ Boolean
49 50 51 |
# File 'lib/maildir.rb', line 49 def valid_recipient?(recipient) return get_maildir(recipient) end |