Help with IMAP and mime

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 = ‘[email protected]
myAppt.header.to = ‘[email protected]
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

On Sat, Mar 15, 2008 at 7:54 AM, CParticle [email protected] wrote:

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 L.
http://lindsaar.net/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs