Help with IMAP and mime

C

CParticle

I'm trying to create a new mime message via imap but I'm having some
problems getting the formatting down.

I'm using net/imap and rmail to get and put data onto the imap
server. I'd like to set the header correctly so that I can write the
data to the server such that it understand what it is. In this case a
calendar item. The idea being that I could then write a calendar item
directly to my calendar on my exchange server and exchange would treat
it as such.


---Begin Code-----
require 'net/imap'

require 'rubygems'
require 'rmail'


imap = Net::IMAP.new('myserver')

imap.login('username', 'password')

imap.select('Calendar-folder')

myAppt = RMail::Message.new
myAppt.header.date = Time.now
myAppt.header.from = '(e-mail address removed)'
myAppt.header.to = '(e-mail address removed)'
myAppt.header.subject = 'Ruby test appointment'
myAppt.header.add('Content-Type', 'MULTIPART/ALTERNATIVE')
part = RMail::Message.new
part.header.add('Content-Type', 'TEXT/CALENDAR', nil, 'param' =>
'{"METHOD" => "REQUEST"}')
part.header.add('Content-class', 'urn:content-classes:appointment')
part.body = vCard
myAppt.add_part(part)

imap.append("Calendar-folder", RMail::Serialize.write('', myAppt),
[:Seen])
---End Code-----

I'm particularly concerned with how to get the param set properly.
----------------------------------------------
I pulled some data from the server using imap.fetch(message_id,
"BODY")

This is what I would like to get the header to look like

#<struct Net::IMAP::FetchData seqno=1, attr={"BODY"=>#<struct
Net::IMAP::BodyTypeMultipart media_type="MULTIPART",
subtype="ALTERNATIVE", parts=[#<struct Net::IMAP::BodyTypeText
media_type="TEXT", subtype="CALENDAR", param={"METHOD"=>"REQUEST"},
content_id=nil, description=nil, encoding="8BIT", size=1279, lines=22,
md5=nil, disposition=nil, language=nil, extension=nil>], param=nil,
disposition=nil, language=nil, extension=nil>}>

---------------------------------------------
This is what I'm managing to create

#<struct Net::IMAP::FetchData seqno=4, attr={"FLAGS"=>[:Seen],
"BODY"=>#<struct Net::IMAP::BodyTypeMultipart media_type="MULTIPART",
subtype="ALTERNATIVE", parts=[#<struct Net::IMAP::BodyTypeText
media_type="TEXT", subtype="CALENDAR", param={"PARAM"=>"{"},
content_id=nil, description=nil, encoding="7BIT", size=1761, lines=30,
md5=nil, disposition=nil, language=nil, extension=nil>], param=nil,
disposition=nil, language=nil, extension=nil>}>



Thanks for any help you can give.
CParticle
 
M

Mikel Lindsaar

I'm using net/imap and rmail to get and put data onto the imap
server. I'd like to set the header correctly so that I can write the
data to the server such that it understand what it is. In this case a
calendar item. The idea being that I could then write a calendar item
directly to my calendar on my exchange server and exchange would treat
it as such.

I don't know if this is exactly what you need, but you can do that
with TMail with:

irb(main):001:0> require 'rubygems'
irb(main):002:0> require 'tmail'

irb(main):003:0> mail = TMail::Mail.new

irb(main):004:0> mail['header'] = 'Content-Type=text/calendar,
param={"METHOD" => "REQUEST"}'
=> "Content-Type=text/calendar, param={\"METHOD\" => \"REQUEST\"}"
irb(main):005:0> puts mail.encoded
Header: Content-Type=text/calendar, param={"METHOD" => "REQUEST"}


Would mean using TMail, it is heavier than RMail, both are good, YMMV.

You might also want to get onto the TMail Talk mailing list or have a
look through the recently updated RDocs at the website;
http://tmail.rubyforge.org/


Mikel Lindsaar
http://lindsaar.net/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top