使用iCal4j在iCal中使用HTML

时间:2010-12-02 15:08:52

标签: java outlook outlook-2007 icalendar vcalendar

是否有可能将html添加到vevent的描述中。

我生成VCALENDAR,其中VEVENT带有描述。我使用Ical4j发送了包含ICS

的电子邮件

这是我尝试做的事情:

BEGIN:VCALENDAR
PRODID:-//----//Calendar 1.0//ES
VERSION:2.0
METHOD:REQUEST
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20101202T145512Z
UID:20101202T145513Z-project@myPc
DESCRIPTION:ALTREP="CID:content-id-here":BlaBla
LOCATION:Room 2
SUMMARY:Confirmation
DTSTART:20110115T180000
DTEND:20110115T184500
ATTENDEE;ROLE=REQ-PARTICIPANT:mailto:foo@bar.com
ORGANIZER;SENT-BY=EyeContact:mailto:foo@bar.com
END:VEVENT
END:VCALENDAR

Content-Type:text/html
Content-Id:content-id-here

   <html>
     <head>
      <title></title>
     </head>
     <body>
       <p>
         <b>Example</b>
       </p>
     </body>
   </html>

现在它只显示HTML代码。

上面的日历我放入了一个MultiPart

message.addHeaderLine("method=REQUEST");
message.addHeaderLine("charset=UTF-8");
message.addHeaderLine("component=vevent");
message.setFrom(new InternetAddress(fromAddress));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(app.getPanelist().getEmail()));
message.setSubject(subject);
Multipart mp = new MimeMultipart();
MimeBodyPart iCalAttachment = new MimeBodyPart();
iCalAttachment.setDataHandler(new DataHandler(new ByteArrayDataSource(new ByteArrayInputStream(invite), "text/calendar;method=REQUEST;charset=\"UTF-8\"")));
mp.addBodyPart(iCalAttachment);
message.setContent(mp);

我会错过一部分还是不可能?

编辑 - 我尝试用iCal4j做什么(使用Altrep)

ParameterList params = new ParameterList();     
URI uri = new URI("CID:content-id-here");
params.add(new AltRep(uri));
vEvent.getProperties().add(new Description(params,_content));

但是上面的代码我被困住了。有人建议将HTML与iCall4j结合使用

2 个答案:

答案 0 :(得分:3)

我在这个blogspot中找到了解决方案:

http://valermicle.blogspot.com/2009/02/i-was-searching-for-documentations-on.html

以正确的方式使用MultiPart解决了问题

答案 1 :(得分:2)

查看iCalendar规范,看起来您需要“替代文字表示”,请参阅RFC 5545 Section 3.2.1

  

示例:

   DESCRIPTION;ALTREP="CID:part3.msg.970415T083000@example.com":
    Project XYZ Review Meeting will include the following agenda
     items: (a) Market Overview\, (b) Finances\, (c) Project Man
    agement
     

“ALTREP”属性参数值可能指向“text / html”         内容部分。

   Content-Type:text/html
   Content-Id:<part3.msg.970415T083000@example.com>

   <html>
     <head>
      <title></title>
     </head>
     <body>
       <p>
         <b>Project XYZ Review Meeting</b> will include
         the following agenda items:
         <ol>
           <li>Market Overview</li>
           <li>Finances</li>
           <li>Project Management</li>
         </ol>
       </p>
     </body>
   </html>