mailr/lib/imap_message.rb

92 lines
1.8 KiB
Ruby
Raw Normal View History

2011-07-27 20:34:30 +02:00
require 'net/imap'
module ImapMessageModule
2011-08-02 23:12:17 +02:00
class IMAPAddress
attr_accessor :name,:mailbox,:host
def initialize()
name = ""
mailbox = ""
host = ""
end
def self.from_address(addr)
a = IMAPAddress.new()
a.name = addr.name || ""
a.mailbox = addr.mailbox || ""
a.host = addr.host || ""
a
end
def to_db
name + "#" + mailbox + "#" + host
end
def self.parse(addr)
a = IMAPAddress.new()
f = addr.split("#")
a.name = f[0]
a.mailbox = f[1]
a.host = f[2]
a
end
def friendly
if name.empty?
mailbox + host
else
name
end
end
end
2011-08-16 20:05:58 +02:00
class IMAPMessage
@@fetch_attr = ['ENVELOPE','BODYSTRUCTURE', 'FLAGS', 'UID', 'RFC822.SIZE']
2011-08-26 22:59:43 +02:00
#@@fetch_attr = ['RFC822','FLAGS', 'UID', 'RFC822.SIZE']
# attr_accessor :envelope,:uid,:content_type,:size,:unseen,:from,:message_id,:to,:from,:subject,:date
#
# def initialize
# end
#
# def self.fromImap(message)
# m = IMAPMessage.new
# envelope = message.attr['ENVELOPE']
# m.envelope = envelope
# m.message_id = envelope.message_id
# m.date = envelope.date
# m.subject = envelope.subject
# m.uid = message.attr['UID']
# #content_type = m.attr['BODYSTRUCTURE'].multipart? ? 'multipart' : 'text'
# m.content_type = message.attr['BODYSTRUCTURE'].media_type.downcase
# m.size = message.attr['RFC822.SIZE']
# m.unseen = !(message.attr['FLAGS'].member? :Seen)
# m.from = IMAPAddress.from_address(envelope.from[0])
# m.to = IMAPAddress.from_address(envelope.to[0])
# m
# end
#
2011-08-16 20:05:58 +02:00
def self.fetch_attr
@@fetch_attr
end
2011-08-26 22:59:43 +02:00
#
# def from_to_db
# from.to_db
# end
#
# def to_to_db
# to.to_db
# end
2011-08-24 19:20:13 +02:00
2011-08-16 20:05:58 +02:00
end
2011-08-24 19:20:13 +02:00
2011-07-27 20:34:30 +02:00
end