Class: Message
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Message
- Defined in:
- app/models/message.rb
Class Method Summary collapse
-
.from_message(mess, recipient = nil, sender = nil) ⇒ Object
(also: parse)
Processes a Gurgitate::Mailmessage object or the text of a message and creates a new Message object.
Instance Method Summary collapse
- #bounce ⇒ Object
-
#deliver(*smtpdetails) ⇒ Object
Delivers a message with the optional parameter hash
smtpdetails
. -
#messagetext(smtpdetails = {}) ⇒ Object
Returns the text of the message that would be sent out by the “deliver” message.
-
#to_s ⇒ Object
Returns the text of the current message.
Class Method Details
.from_message(mess, recipient = nil, sender = nil) ⇒ Object Also known as: parse
Processes a Gurgitate::Mailmessage object or the text of a message and creates a new Message object.
mess
-
Either a Gurgitate::Mailmessage object (with envelope
information intact), or the text of a mail message (in which case the envelope information must be supplied)
recipient
-
The envelope recipient (SMTP’s RCPT To:) of the mail
message.
sender
-
The envelope sender (SMTP’s MAIL From:) of the mail
message.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/message.rb', line 71 def (mess, recipient=nil, sender=nil) # This method is way too long, sorry if Gurgitate::Mailmessage === mess then = self.new . = mess . = mess addr = Address.find_or_create_by_address mess.from if addr.new_record? then addr.save end .address = addr .headers = mess.headers.to_s .body = mess.body.to_s .parent = find_parent mess .envelope_from = mess.from .envelope_to = mess.to.map do |t| if Gurgitate::Header === t t.contents else t end end .address.save if .address.new_record? ml, type = Mailinglist.find_by_address(.envelope_to[0]) if ml then if type == :mail then .mailinglist = ml .save end end return elsif String === mess then Gurgitate::Mailmessage.new(mess,recipient,sender) end end |
Instance Method Details
#bounce ⇒ Object
311 312 313 314 |
# File 'app/models/message.rb', line 311 def bounce # TODO nil end |
#deliver(*smtpdetails) ⇒ Object
Delivers a message with the optional parameter hash smtpdetails
.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'app/models/message.rb', line 269 def deliver(*smtpdetails) if Hash === smtpdetails[0] then smtpdetails = smtpdetails[0] else smtpdetails = {} end # Hm, not sure why this is *here* instead of somewhere # else. Fix later. # # (This should actually be in the database somewhere, I'm thinking.) smtpserver = SysConfig.smtpserver smtpport = SysConfig.smtpport mysmtpname = SysConfig.mysmtpname if smtpdetails.has_key? :smtpserver then smtpserver = smtpdetails[:smtpserver] end if smtpdetails.has_key? :smtpport then smtpport = smtpdetails[:smtpport] || 25 end if mailinglist.closed? unless mailinglist.user.mailinglist.has_address? \ self.envelope_from or \ mailinglist.user.address == self.envelope_from then return bounce end end begin generate_envelope_data rescue UnregisteredUserException return bounce end Net::SMTP.start(smtpserver, smtpport, mysmtpname) do |smtp| smtp. (smtpdetails), self.envelope_from, self.envelope_to end end |
#messagetext(smtpdetails = {}) ⇒ Object
Returns the text of the message that would be sent out by the “deliver” message. This might have headers rewritten to reflect mail aliases.
254 255 256 257 258 259 260 261 262 263 264 |
# File 'app/models/message.rb', line 254 def (smtpdetails={}) if smtpdetails.has_key? :custom_message return smtpdetails[:custom_message] end if mailinglist.canonical_address? or mailinglist.closed? then proxify_addresses else to_s end end |
#to_s ⇒ Object
Returns the text of the current message
317 318 319 |
# File 'app/models/message.rb', line 317 def to_s headers.to_s.chomp.chomp+"\n\n"+body.to_s end |