Class: Mapi::Attachment
- Inherits:
-
Item
- Object
- Item
- Mapi::Attachment
show all
- Defined in:
- lib/mapi.rb,
lib/mapi/convert/note-mime.rb,
lib/mapi/convert/note-tmail.rb
Overview
a general attachment class. is subclassed by Msg and Pst attachment classes
Instance Attribute Summary
Attributes inherited from Item
#properties
Instance Method Summary
collapse
Methods inherited from Item
#initialize
Constructor Details
This class inherits a constructor from Mapi::Item
Instance Method Details
#data ⇒ Object
27
28
29
|
# File 'lib/mapi.rb', line 27
def data
@embedded_msg || @embedded_ole || props.attach_data
end
|
#filename ⇒ Object
23
24
25
|
# File 'lib/mapi.rb', line 23
def filename
props.attach_long_filename || props.attach_filename
end
|
#inspect ⇒ Object
41
42
43
44
45
|
# File 'lib/mapi.rb', line 41
def inspect
"#<#{self.class.to_s[/\w+$/]}" +
(filename ? " filename=#{filename.inspect}" : '') +
(@embedded_ole ? " embedded_type=#{@embedded_ole.embedded_type.inspect}" : '') + ">"
end
|
#save(io) ⇒ Object
with new stream work, its possible to not have the whole thing in memory at one time, just to save an attachment
a = msg.attachments.first a.save open(File.basename(a.filename || ‘attachment’), ‘wb’)
36
37
38
39
|
# File 'lib/mapi.rb', line 36
def save io
raise "can only save binary data blobs, not ole dirs" if @embedded_ole
data.each_read { |chunk| io << chunk }
end
|
#to_mime ⇒ Object
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/mapi/convert/note-mime.rb', line 225
def to_mime
mimetype = props.attach_mime_tag || 'application/octet-stream'
mime = Mime.new "Content-Type: #{mimetype}\r\n\r\n"
mime.['Content-Disposition'] = [%{attachment; filename="#{filename}"}]
mime.['Content-Transfer-Encoding'] = ['base64']
mime.['Content-Location'] = [props.attach_content_location] if props.attach_content_location
mime.['Content-ID'] = [props.attach_content_id] if props.attach_content_id
data_str = if @embedded_msg
mime.['Content-Type'] = 'message/rfc822'
mime..delete 'Content-Transfer-Encoding'
mime.['Content-Disposition'] = [%{attachment; filename="#{@embedded_msg.subject}"}]
@embedded_msg.to_mime.to_s
elsif @embedded_ole
io = StringIO.new
Ole::Storage.new io do |ole|
ole.root.type = :dir
Ole::Storage::Dirent.copy @embedded_ole, ole.root
end
io.string
else
data.read.to_s rescue ''
end
mime.body.replace @embedded_msg ? data_str : Base64.encode64(data_str).gsub(/\n/, "\r\n")
mime
end
|
#to_tmail ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/mapi/convert/note-tmail.rb', line 237
def to_tmail
mimetype = props.attach_mime_tag || 'application/octet-stream'
part = TMail::Mail.parse "Content-Type: #{mimetype}\r\n\r\n"
part['Content-Disposition'] = %{attachment; filename="#{filename}"}
part['Content-Transfer-Encoding'] = 'base64'
part['Content-Location'] = props.attach_content_location if props.attach_content_location
part['Content-ID'] = props.attach_content_id if props.attach_content_id
data_str = if @embedded_msg
raise NotImplementedError
mime.['Content-Type'] = 'message/rfc822'
mime..delete 'Content-Transfer-Encoding'
mime.['Content-Disposition'] = [%{attachment; filename="#{@embedded_msg.subject}"}]
@embedded_msg.to_mime.to_s
elsif @embedded_ole
raise NotImplementedError
io = StringIO.new
Ole::Storage.new io do |ole|
ole.root.type = :dir
Ole::Storage::Dirent.copy @embedded_ole, ole.root
end
io.string
else
data.read.to_s
end
part.body = @embedded_msg ? data_str : Base64.encode64(data_str).gsub(/\n/, "\r\n")
part
end
|