forked from aquasync/ruby-msg
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.rb
More file actions
62 lines (55 loc) · 1.52 KB
/
convert.rb
File metadata and controls
62 lines (55 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- encoding : ASCII-8BIT -*-
# we have two different "backends" for note conversion. we're sticking with
# the current (home grown) mime one until the tmail version is suitably
# polished.
require 'mapi/convert/note-mime'
require 'mapi/convert/contact'
module Mapi
class Message
CONVERSION_MAP = {
'text/x-vcard' => [:to_vcard, 'vcf'],
'message/rfc822' => [:to_mime, 'eml'],
'text/plain' => [:to_post, 'txt']
# ...
}
# get the mime type of the message.
def mime_type
case props.message_class #.downcase <- have a feeling i saw other cased versions
when 'IPM.Contact'
# apparently "text/directory; profile=vcard" is what you're supposed to use
'text/x-vcard'
when 'IPM.Note'
'message/rfc822'
when 'IPM.Post'
'text/plain'
when 'IPM.StickyNote'
'text/plain' # hmmm....
else
Mapi::Log.warn 'unknown message_class - %p' % props.message_class
nil
end
end
def convert
type = mime_type
unless pair = CONVERSION_MAP[type]
raise 'unable to convert message with mime type - %p' % type
end
send pair.first
end
# should probably be moved to mapi/convert/post
class Post
# not really sure what the pertinent properties are. we just do nothing for now...
def initialize message
@message = message
end
def to_s
# should maybe handle other types, like html body. need a better format for post
# probably anyway, cause a lot of meta data is getting chucked.
@message.props.body
end
end
def to_post
Post.new self
end
end
end