Class: Hermeneutics::Message
- Inherits:
-
Mime
- Object
- Mime
- Hermeneutics::Message
show all
- Defined in:
- lib/hermeneutics/message.rb
Direct Known Subclasses
Mail
Defined Under Namespace
Classes: Header, Headers, ParseError
Constant Summary
collapse
- MIME =
"message/rfc822"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Mime
find, inherited
Constructor Details
#initialize(headers, body) ⇒ Message
Returns a new instance of Message.
516
517
518
519
|
# File 'lib/hermeneutics/message.rb', line 516
def initialize , body
@headers, @body = , body
@headers ||= Headers.create
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
527
528
529
530
531
532
533
534
|
# File 'lib/hermeneutics/message.rb', line 527
def method_missing sym, *args, &block
case sym
when /\Ah_(.*)/, /\Aheader_(.*)/ then
$1.to_sym, *args
else
super
end
end
|
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
514
515
516
|
# File 'lib/hermeneutics/message.rb', line 514
def body
@body
end
|
Returns the value of attribute headers.
514
515
516
|
# File 'lib/hermeneutics/message.rb', line 514
def
@headers
end
|
Class Method Details
.create ⇒ Object
478
479
480
|
# File 'lib/hermeneutics/message.rb', line 478
def create
new nil, nil
end
|
.parse(input) ⇒ Object
472
473
474
475
476
|
# File 'lib/hermeneutics/message.rb', line 472
def parse input
parse_hb input do |h,b|
new h, b
end
end
|
Instance Method Details
#[](name, type = nil) ⇒ Object
543
544
545
|
# File 'lib/hermeneutics/message.rb', line 543
def [] name, type = nil
@headers[ name, type]
end
|
#body_binary=(body) ⇒ Object
602
603
604
605
|
# File 'lib/hermeneutics/message.rb', line 602
def body_binary= body
@headers.replace :content_transfer_encoding, "base64"
@body = [ body].pack "m*"
end
|
#body_decoded ⇒ Object
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
# File 'lib/hermeneutics/message.rb', line 580
def body_decoded
r = case transfer_encoding
when "quoted-printable" then
(@body.unpack "M").join
when "base64" then
(@body.unpack "m").join
else
@body.chomp
end
if (c = @headers.content_type) and (cs = c[ :charset]) then
r.force_encoding cs
end
r
end
|
#body_text=(body) ⇒ Object
595
596
597
598
599
600
|
# File 'lib/hermeneutics/message.rb', line 595
def body_text= body
body = body.to_s
@headers.replace :content_type, "text/plain", charset: body.encoding
@headers.replace :content_transfer_encoding, "quoted-printable"
@body = [ body].pack "M*"
end
|
#has?(name) ⇒ Boolean
Also known as:
538
539
540
|
# File 'lib/hermeneutics/message.rb', line 538
def has? name
@headers.has? name
end
|
521
522
523
|
# File 'lib/hermeneutics/message.rb', line 521
def sym, type = nil
@headers.field sym, type
end
|
#inspect ⇒ Object
552
553
554
555
556
557
558
559
|
# File 'lib/hermeneutics/message.rb', line 552
def inspect
r = ""
r << "#<#{self.class}:"
r << "0x%x" % (object_id<<1)
r << " headers:#{@headers.length}"
r << " multipart" if is_multipart?
r << ">"
end
|
#is_multipart? ⇒ Boolean
Also known as:
mp?
547
548
549
|
# File 'lib/hermeneutics/message.rb', line 547
def is_multipart?
Multipart === @body
end
|
#to_s ⇒ Object
561
562
563
564
565
566
567
568
569
570
571
572
573
|
# File 'lib/hermeneutics/message.rb', line 561
def to_s
r = ""
if is_multipart? then
c = @headers.field :content_type
u = @body.boundary
if c[ :boundary] != u then
@headers.replace :content_type, c.fulltype, boundary: u
end
end
r << @headers.to_s << "\n" << @body.to_s
r.ends_with? "\n" or r << "\n"
r
end
|
#transfer_encoding ⇒ Object
575
576
577
578
|
# File 'lib/hermeneutics/message.rb', line 575
def transfer_encoding
c = @headers[ :content_transfer_encoding]
c.caption if c
end
|