Class: TMail::Mail

Inherits:
Object
  • Object
show all
Includes:
StrategyInterface, TextUtils
Defined in:
lib/action_mailer/vendor/tmail/obsolete.rb,
lib/action_mailer/vendor/tmail/net.rb,
lib/action_mailer/vendor/tmail/mail.rb,
lib/action_mailer/vendor/tmail/facade.rb,
lib/action_mailer/vendor/tmail/obsolete.rb

Overview

facade.rb

Constant Summary collapse

NOSEND_FIELDS =
%w(
  received
  bcc
)
ALLOW_MULTIPLE =
{
  'received'          => true,
  'resent-date'       => true,
  'resent-from'       => true,
  'resent-sender'     => true,
  'resent-to'         => true,
  'resent-cc'         => true,
  'resent-bcc'        => true,
  'resent-message-id' => true,
  'comments'          => true,
  'keywords'          => true
}
USE_ARRAY =
ALLOW_MULTIPLE
FIELD_ORDER =
%w(
  return-path received
  resent-date resent-from resent-sender resent-to
  resent-cc resent-bcc resent-message-id
  date from sender reply-to to cc bcc
  message-id in-reply-to references
  subject comments keywords
  mime-version content-type content-transfer-encoding
  content-disposition content-description
)

Constants included from TextUtils

TextUtils::ATOM_UNSAFE, TextUtils::CONTROL_CHAR, TextUtils::MESSAGE_ID, TextUtils::MIME_ENCODED, TextUtils::MONTH, TextUtils::NKF_FLAGS, TextUtils::PHRASE_UNSAFE, TextUtils::RFC2231_ENCODED, TextUtils::TOKEN_UNSAFE, TextUtils::WDAY, TextUtils::ZONESTR_TABLE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TextUtils

#atom_safe?, #decode_RFC2231, #decode_params, #join_domain, #message_id?, #mime_encoded?, #quote_atom, #quote_phrase, #quote_token, #time2str, #timezone_string_to_unixtime, #to_kcode, #token_safe?

Methods included from StrategyInterface

#accept_strategy, create_dest, #decoded, #encoded

Constructor Details

#initialize(port = nil, conf = DEFAULT_CONFIG) ⇒ Mail

Returns a new instance of Mail.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 37

def initialize( port = nil, conf = DEFAULT_CONFIG )
  @port = port || StringPort.new
  @config = Config.to_config(conf)

  @header      = {}
  @body_port   = nil
  @body_parsed = false
  @epilogue    = ''
  @parts       = []

  @port.ropen {|f|
      parse_header f
      parse_body f unless @port.reproducible?
  }
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



53
54
55
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 53

def port
  @port
end

Class Method Details

.boundaryObject



108
109
110
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 108

def Mail.boundary
  ::TMail.new_boundary
end

.load(fname) ⇒ Object Also known as: load_from, loadfrom



25
26
27
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 25

def load( fname )
  new(FilePort.new(fname))
end

.msgidObject



112
113
114
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 112

def Mail.msgid
  ::TMail.new_message_id
end

.parse(str) ⇒ Object



32
33
34
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 32

def parse( str )
  new(StringPort.new(str))
end

Instance Method Details

#[](key) ⇒ Object Also known as: fetch



142
143
144
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 142

def []( key )
  @header[key.downcase]
end

#[]=(key, val) ⇒ Object Also known as: store



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 148

def []=( key, val )
  dkey = key.downcase

  if val.nil?
    @header.delete dkey
    return nil
  end

  case val
  when String
    header = new_hf(key, val)
  when HeaderField
    ;
  when Array
    ALLOW_MULTIPLE.include? dkey or
            raise ArgumentError, "#{key}: Header must not be multiple"
    @header[dkey] = val
    return val
  else
    header = new_hf(key, val.to_s)
  end
  if ALLOW_MULTIPLE.include? dkey
    (@header[dkey] ||= []).push header
  else
    @header[dkey] = header
  end

  val
end

#accept(strategy) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 72

def accept( strategy )
  with_multipart_encoding(strategy) {
      ordered_each do |name, field|
        next if field.empty?
        strategy.header_name canonical(name)
        field.accept strategy
        strategy.puts
      end
      strategy.puts
      body_port().ropen {|r|
          strategy.write r.read
      }
  }
end

#add_dateObject



67
68
69
# File 'lib/action_mailer/vendor/tmail/net.rb', line 67

def add_date
  self.date = Time.now
end

#add_message_id(fqdn = nil) ⇒ Object



63
64
65
# File 'lib/action_mailer/vendor/tmail/net.rb', line 63

def add_message_id( fqdn = nil )
  self.message_id = ::TMail::new_msgid(fqdn)
end

#base64_decodeObject



481
482
483
484
485
486
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 481

def base64_decode
  if /base64/i === self.transfer_encoding('')
    store 'Content-Transfer-Encoding', '8bit'
    self.body = Base64.decode(self.body, @config.strict_base64decode?)
  end
end

#base64_encodeObject



476
477
478
479
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 476

def base64_encode
  store 'Content-Transfer-Encoding', 'Base64'
  self.body = Base64.folding_encode(self.body)
end

#bcc(default = nil) ⇒ Object



154
155
156
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 154

def bcc( default = nil )
  addrs2specs(bcc_addrs(nil)) || default
end

#bcc=(*strs) ⇒ Object



166
167
168
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 166

def bcc=( *strs )
  set_string_array_attr 'Bcc', strs
end

#bcc_addrs(default = nil) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 126

def bcc_addrs( default = nil )
  if h = @header['bcc']
    h.addrs
  else
    default
  end
end

#bcc_addrs=(arg) ⇒ Object



142
143
144
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 142

def bcc_addrs=( arg )
  set_addrfield 'bcc', arg
end

#bodyObject Also known as: preamble



323
324
325
326
327
328
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 323

def body
  parse_body
  @body_port.ropen {|f|
      return f.read
  }
end

#body=(str) ⇒ Object Also known as: preamble=



330
331
332
333
334
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 330

def body=( str )
  parse_body
  @body_port.wopen {|f| f.write str }
  str
end

#body_portObject



314
315
316
317
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 314

def body_port
  parse_body
  @body_port
end

#cc(default = nil) ⇒ Object



150
151
152
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 150

def cc( default = nil )
  addrs2specs(cc_addrs(nil)) || default
end

#cc=(*strs) ⇒ Object



162
163
164
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 162

def cc=( *strs )
  set_string_array_attr 'Cc', strs
end

#cc_addrs(default = nil) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 118

def cc_addrs( default = nil )
  if h = @header['cc']
    h.addrs
  else
    default
  end
end

#cc_addrs=(arg) ⇒ Object



138
139
140
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 138

def cc_addrs=( arg )
  set_addrfield 'cc', arg
end

#charset(default = nil) ⇒ Object



391
392
393
394
395
396
397
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 391

def charset( default = nil )
  if h = @header['content-type']
    h['charset'] or default
  else
    default
  end
end

#charset=(str) ⇒ Object



399
400
401
402
403
404
405
406
407
408
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 399

def charset=( str )
  if str
    if h = @header[ 'content-type' ]
      h['charset'] = str
    else
      store 'Content-Type', "text/plain; charset=#{str}"
    end
  end
  str
end

#clearObject



223
224
225
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 223

def clear
  @header.clear
end

#content_type(default = nil) ⇒ Object



338
339
340
341
342
343
344
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 338

def content_type( default = nil )
  if h = @header['content-type']
    h.content_type || default
  else
    default
  end
end

#create_empty_mailObject



111
112
113
# File 'lib/action_mailer/vendor/tmail/net.rb', line 111

def create_empty_mail
  self.class.new(StringPort.new(''), @config)
end

#create_forwardObject



134
135
136
# File 'lib/action_mailer/vendor/tmail/net.rb', line 134

def create_forward
  setup_forward create_empty_mail()
end

#create_replyObject

utils



465
466
467
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 465

def create_reply
  setup_reply create_empty_mail()
end

#date(default = nil) ⇒ Object

date time



80
81
82
83
84
85
86
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 80

def date( default = nil )
  if h = @header['date']
    h.date
  else
    default
  end
end

#date=(time) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 88

def date=( time )
  if time
    store 'Date', time2str(time)
  else
    @header.delete 'date'
  end
  time
end

#delete(key) ⇒ Object



227
228
229
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 227

def delete( key )
  @header.delete key.downcase
end

#delete_ifObject



231
232
233
234
235
236
237
238
239
240
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 231

def delete_if
  @header.delete_if do |key,val|
    if Array === val
      val.delete_if {|v| yield key, v }
      val.empty?
    else
      yield key, val
    end
  end
end

#delete_no_send_fieldsObject



56
57
58
59
60
61
# File 'lib/action_mailer/vendor/tmail/net.rb', line 56

def delete_no_send_fields
  NOSEND_FIELDS.each do |nm|
    delete nm
  end
  delete_if {|n,v| v.empty? }
end

#destinations(default = nil) ⇒ Object



489
490
491
492
493
494
495
496
497
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 489

def destinations( default = nil )
  ret = []
  %w( to cc bcc ).each do |nm|
    if h = @header[nm]
      h.addrs.each {|i| ret.push i.address }
    end
  end
  ret.empty? ? default : ret
end

#disposition(default = nil) ⇒ Object Also known as: content_disposition



429
430
431
432
433
434
435
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 429

def disposition( default = nil )
  if h = @header['content-disposition']
    h.disposition || default
  else
    default
  end
end

#disposition_param(name, default = nil) ⇒ Object



453
454
455
456
457
458
459
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 453

def disposition_param( name, default = nil )
  if h = @header['content-disposition']
    h[name] || default
  else
    default
  end
end

#each(&block) ⇒ Object



319
320
321
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 319

def each( &block )
  body_port().ropen {|f| f.each(&block) }
end

#each_destination(&block) ⇒ Object Also known as: each_dest



499
500
501
502
503
504
505
506
507
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 499

def each_destination( &block )
  destinations([]).each do |i|
    if Address === i
      yield i
    else
      i.each(&block)
    end
  end
end

#each_field(&block) ⇒ Object Also known as: each_value



194
195
196
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 194

def each_field( &block )
  @header.values.flatten.each(&block)
end

#each_headerObject Also known as: each_pair



180
181
182
183
184
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 180

def each_header
  @header.each do |key, val|
    [val].flatten.each {|v| yield key, v }
  end
end

#each_header_name(&block) ⇒ Object Also known as: each_key



188
189
190
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 188

def each_header_name( &block )
  @header.each_key(&block)
end

#each_part(&block) ⇒ Object



355
356
357
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 355

def each_part( &block )
  parts().each(&block)
end

#epilogueObject



339
340
341
342
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 339

def epilogue
  parse_body
  @epilogue.dup
end

#epilogue=(str) ⇒ Object



344
345
346
347
348
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 344

def epilogue=( str )
  parse_body
  @epilogue = str
  str
end

#error_reply_addresses(default = nil) ⇒ Object



516
517
518
519
520
521
522
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 516

def error_reply_addresses( default = nil )
  if s = sender(nil)
    [s]
  else
    from_addrs(default)
  end
end

#friendly_from(default = nil) ⇒ Object



195
196
197
198
199
200
201
202
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 195

def friendly_from( default = nil )
  h = @header['from']
  a, = h.addrs
  return default unless a
  return a.phrase if a.phrase
  return h.comments.join(' ') unless h.comments.empty?
  a.spec
end

#from(default = nil) ⇒ Object



187
188
189
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 187

def from( default = nil )
  addrs2specs(from_addrs(nil)) || default
end

#from=(*strs) ⇒ Object



191
192
193
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 191

def from=( *strs )
  set_string_array_attr 'From', strs
end

#from_addr(default = nil) ⇒ Object



36
37
38
39
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 36

def from_addr( default = nil )
  addr, = from_addrs(nil)
  addr || default
end

#from_address(default = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 41

def from_address( default = nil )
  if a = from_addr(nil)
    a.spec
  else
    default
  end
end

#from_addrs(default = nil) ⇒ Object

originator



175
176
177
178
179
180
181
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 175

def from_addrs( default = nil )
  if h = @header['from']
    h.addrs
  else
    default
  end
end

#from_addrs=(arg) ⇒ Object Also known as: from_address=



183
184
185
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 183

def from_addrs=( arg )
  set_addrfield 'from', arg
end

#from_phrase(default = nil) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 51

def from_phrase( default = nil )
  if a = from_addr(nil)
    a.phrase
  else
    default
  end
end

#headerObject



138
139
140
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 138

def header
  @header.dup
end

#header_string(name, default = nil) ⇒ Object



18
19
20
21
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 18

def header_string( name, default = nil )
  h = @header[name.downcase] or return default
  h.to_s
end

#in_reply_to(default = nil) ⇒ Object



286
287
288
289
290
291
292
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 286

def in_reply_to( default = nil )
  if h = @header['in-reply-to']
    h.ids
  else
    default
  end
end

#in_reply_to=(*idstrs) ⇒ Object



294
295
296
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 294

def in_reply_to=( *idstrs )
  set_string_array_attr 'In-Reply-To', idstrs
end

#inspectObject



55
56
57
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 55

def inspect
  "\#<#{self.class} port=#{@port.inspect} bodyport=#{@body_port.inspect}>"
end

#key?(key) ⇒ Boolean Also known as: include?, has_key?

Returns:

  • (Boolean)


246
247
248
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 246

def key?( key )
  @header.key? key.downcase
end

#keysObject



242
243
244
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 242

def keys
  @header.keys
end

#main_type(default = nil) ⇒ Object



346
347
348
349
350
351
352
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 346

def main_type( default = nil )
  if h = @header['content-type']
    h.main_type || default
  else
    default
  end
end

#message_id(default = nil) ⇒ Object Also known as: msgid

identity & threading



274
275
276
277
278
279
280
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 274

def message_id( default = nil )
  if h = @header['message-id']
    h.id || default
  else
    default
  end
end

#message_id=(str) ⇒ Object Also known as: msgid=



282
283
284
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 282

def message_id=( str )
  set_string_attr 'Message-Id', str
end

#mime_encodeObject



71
72
73
74
75
76
77
# File 'lib/action_mailer/vendor/tmail/net.rb', line 71

def mime_encode
  if parts.empty?
    mime_encode_singlepart
  else
    mime_encode_multipart true
  end
end

#mime_encode_binary(body) ⇒ Object



95
96
97
98
99
# File 'lib/action_mailer/vendor/tmail/net.rb', line 95

def mime_encode_binary( body )
  self.body = [body].pack('m')
  self.set_content_type 'application', 'octet-stream'
  self.encoding = 'Base64'
end

#mime_encode_multipart(top = true) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/action_mailer/vendor/tmail/net.rb', line 101

def mime_encode_multipart( top = true )
  self.mime_version = '1.0' if top
  self.set_content_type 'multipart', 'mixed'
  e = encoding(nil)
  if e and not /\A(?:7bit|8bit|binary)\z/i === e
    raise ArgumentError,
          'using C.T.Encoding with multipart mail is not permitted'
  end
end

#mime_encode_singlepartObject



79
80
81
82
83
84
85
86
87
# File 'lib/action_mailer/vendor/tmail/net.rb', line 79

def mime_encode_singlepart
  self.mime_version = '1.0'
  b = body
  if NKF.guess(b) != NKF::BINARY
    mime_encode_text b
  else
    mime_encode_binary b
  end
end

#mime_encode_text(body) ⇒ Object



89
90
91
92
93
# File 'lib/action_mailer/vendor/tmail/net.rb', line 89

def mime_encode_text( body )
  self.body = NKF.nkf('-j -m0', body)
  self.set_content_type 'text', 'plain', {'charset' => 'iso-2022-jp'}
  self.encoding = '7bit'
end

#mime_version(default = nil) ⇒ Object

MIME headers



315
316
317
318
319
320
321
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 315

def mime_version( default = nil )
  if h = @header['mime-version']
    h.version || default
  else
    default
  end
end

#mime_version=(m, opt = nil) ⇒ Object



323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 323

def mime_version=( m, opt = nil )
  if opt
    if h = @header['mime-version']
      h.major = m
      h.minor = opt
    else
      store 'Mime-Version', "#{m}.#{opt}"
    end
  else
    store 'Mime-Version', m
  end
  m
end

#multipart?Boolean

Returns:

  • (Boolean)


525
526
527
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 525

def multipart?
  main_type('').downcase == 'multipart'
end

#ordered_eachObject



211
212
213
214
215
216
217
218
219
220
221
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 211

def ordered_each
  list = @header.keys
  FIELD_ORDER.each do |name|
    if list.delete(name)
      [@header[name]].flatten.each {|v| yield name, v }
    end
  end
  list.each do |name|
    [@header[name]].flatten.each {|v| yield name, v }
  end
end

#partsObject



350
351
352
353
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 350

def parts
  parse_body
  @parts
end

#ready_to_sendObject



45
46
47
48
49
# File 'lib/action_mailer/vendor/tmail/net.rb', line 45

def ready_to_send
  delete_no_send_fields
  add_message_id
  add_date
end

#references(default = nil) ⇒ Object



298
299
300
301
302
303
304
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 298

def references( default = nil )
  if h = @header['references']
    h.refs
  else
    default
  end
end

#references=(*strs) ⇒ Object



306
307
308
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 306

def references=( *strs )
  set_string_array_attr 'References', strs
end

#reply_addresses(default = nil) ⇒ Object



512
513
514
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 512

def reply_addresses( default = nil )
  reply_to_addrs(nil) or from_addrs(nil) or default
end

#reply_to(default = nil) ⇒ Object



217
218
219
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 217

def reply_to( default = nil )
  addrs2specs(reply_to_addrs(nil)) || default
end

#reply_to=(*strs) ⇒ Object



221
222
223
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 221

def reply_to=( *strs )
  set_string_array_attr 'Reply-To', strs
end

#reply_to_addrs(default = nil) ⇒ Object



205
206
207
208
209
210
211
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 205

def reply_to_addrs( default = nil )
  if h = @header['reply-to']
    h.addrs
  else
    default
  end
end

#reply_to_addrs=(arg) ⇒ Object



213
214
215
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 213

def reply_to_addrs=( arg )
  set_addrfield 'reply-to', arg
end

#send_text_to(smtp) ⇒ Object



24
25
26
27
28
29
# File 'lib/action_mailer/vendor/tmail/net.rb', line 24

def send_text_to( smtp )
  do_send_to(smtp) do
    ready_to_send
    mime_encode
  end
end

#send_to(smtp) ⇒ Object



18
19
20
21
22
# File 'lib/action_mailer/vendor/tmail/net.rb', line 18

def send_to( smtp )
  do_send_to(smtp) do
    ready_to_send
  end
end

#send_to_0(smtp, from, to) ⇒ Object



39
40
41
42
43
# File 'lib/action_mailer/vendor/tmail/net.rb', line 39

def send_to_0( smtp, from, to )
  smtp.ready(from, to) do |f|
    encoded "\r\n", 'j', f, ''
  end
end

#sender(default) ⇒ Object



242
243
244
245
246
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 242

def sender( default )
  f = @header['sender'] or return default
  a = f.addr            or return default
  a.spec
end

#sender=(str) ⇒ Object



248
249
250
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 248

def sender=( str )
  set_string_attr 'Sender', str
end

#sender_addr(default = nil) ⇒ Object



226
227
228
229
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 226

def sender_addr( default = nil )
  f = @header['sender'] or return default
  f.addr                or return default
end

#sender_addr=(addr) ⇒ Object



231
232
233
234
235
236
237
238
239
240
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 231

def sender_addr=( addr )
  if addr
    h = HeaderField.internal_new('sender', @config)
    h.addr = addr
    @header['sender'] = h
  else
    @header.delete 'sender'
  end
  addr
end

#set_content_type(str, sub = nil, param = nil) ⇒ Object Also known as: content_type=



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 362

def set_content_type( str, sub = nil, param = nil )
  if sub
    main, sub = str, sub
  else
    main, sub = str.split(%r</>, 2)
    raise ArgumentError, "sub type missing: #{str.inspect}" unless sub
  end
  if h = @header['content-type']
    h.main_type = main
    h.sub_type  = sub
    h.params.clear
  else
    store 'Content-Type', "#{main}/#{sub}"
  end
  @header['content-type'].params.replace param if param

  str
end

#set_disposition(str, params = nil) ⇒ Object Also known as: disposition=, set_content_disposition, content_disposition=



439
440
441
442
443
444
445
446
447
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 439

def set_disposition( str, params = nil )
  if h = @header['content-disposition']
    h.disposition = str
    h.params.clear
  else
    h = store('Content-Disposition', str)
  end
  h.params.replace params if params
end

#setup_forward(mail) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/action_mailer/vendor/tmail/net.rb', line 138

def setup_forward( mail )
  m = Mail.new(StringPort.new(''))
  m.body = decoded
  m.set_content_type 'message', 'rfc822'
  m.encoding = encoding('7bit')
  mail.parts.push m
end

#setup_reply(m) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/action_mailer/vendor/tmail/net.rb', line 119

def setup_reply( m )
  if tmp = reply_addresses(nil)
    m.to_addrs = tmp
  end

  mid = message_id(nil)
  tmp = references(nil) || []
  tmp.push mid if mid
  m.in_reply_to = [mid] if mid
  m.references = tmp unless tmp.empty?
  m.subject = 'Re: ' + subject('').sub(/\A(?:\s*re:)+/i, '')

  m
end

#strftime(fmt, default = nil) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 97

def strftime( fmt, default = nil )
  if t = date
    t.strftime(fmt)
  else
    default
  end
end

#sub_type(default = nil) ⇒ Object



354
355
356
357
358
359
360
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 354

def sub_type( default = nil )
  if h = @header['content-type']
    h.sub_type || default
  else
    default
  end
end

#subject(default = nil) ⇒ Object

subject



257
258
259
260
261
262
263
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 257

def subject( default = nil )
  if h = @header['subject']
    h.body
  else
    default
  end
end

#subject=(str) ⇒ Object



265
266
267
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 265

def subject=( str )
  set_string_attr 'Subject', str
end

#to(default = nil) ⇒ Object



146
147
148
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 146

def to( default = nil )
  addrs2specs(to_addrs(nil)) || default
end

#to=(*strs) ⇒ Object



158
159
160
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 158

def to=( *strs )
  set_string_array_attr 'To', strs
end

#to_addrs(default = nil) ⇒ Object

destination



110
111
112
113
114
115
116
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 110

def to_addrs( default = nil )
  if h = @header['to']
    h.addrs
  else
    default
  end
end

#to_addrs=(arg) ⇒ Object



134
135
136
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 134

def to_addrs=( arg )
  set_addrfield 'to', arg
end

#transfer_encoding(default = nil) ⇒ Object Also known as: encoding, content_transfer_encoding



411
412
413
414
415
416
417
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 411

def transfer_encoding( default = nil )
  if h = @header['content-transfer-encoding']
    h.encoding || default
  else
    default
  end
end

#transfer_encoding=(str) ⇒ Object Also known as: encoding=, content_transfer_encoding=



419
420
421
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 419

def transfer_encoding=( str )
  set_string_attr 'Content-Transfer-Encoding', str
end

#type_param(name, default = nil) ⇒ Object



383
384
385
386
387
388
389
# File 'lib/action_mailer/vendor/tmail/facade.rb', line 383

def type_param( name, default = nil )
  if h = @header['content-type']
    h[name] || default
  else
    default
  end
end

#value?(val) ⇒ Boolean Also known as: has_value?

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 24

def value?( val )
  HeaderField === val or return false

  [ @header[val.name.downcase] ].flatten.include? val
end

#valuesObject



18
19
20
21
22
# File 'lib/action_mailer/vendor/tmail/obsolete.rb', line 18

def values
  ret = []
  each_field {|v| ret.push v }
  ret
end

#values_at(*args) ⇒ Object Also known as: indexes, indices



250
251
252
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 250

def values_at( *args )
  args.map {|k| @header[k.downcase] }.flatten
end

#write_back(eol = "\n", charset = 'e') ⇒ Object



67
68
69
70
# File 'lib/action_mailer/vendor/tmail/mail.rb', line 67

def write_back( eol = "\n", charset = 'e' )
  parse_body
  @port.wopen {|stream| encoded eol, charset, stream }
end