Hello,
Using this, you no longer use <body> but <multipart> tags, the patch is
pretty understandable. It would be nice you take it and submit a proper
patch for the current SVN trunk !
Hope it helps,
Rémi
On Fri, Jul 10, 2009 at 22:32, <webp...@tigris.org> wrote:
> I'd love to get that multi-part patch. Can you post the code?
>
> thanks
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2370212
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2371413
--- com.noelios.restlet.ext.javamail_1.4
original/com/noelios/restlet/ext/javamail/RepresentationMessage.java
2008-10-28 17:36:28.000000000 +0100
+++
com.noelios.restlet.ext.javamail_1.4/com/noelios/restlet/ext/javamail/RepresentationMessage.java
2008-09-15 10:25:07.000000000 +0200
@@ -1,5 +1,6 @@
/**
* Copyright 2005-2008 Noelios Technologies.
+ * Copyright 2008 GIDE.
*
* The contents of this file are subject to the terms of the following open
* source licenses: LGPL 3.0 or LGPL 2.1 or CDDL 1.0 (the "Licenses"). You can
@@ -35,19 +36,22 @@
import javax.mail.Session;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
import org.restlet.resource.DomRepresentation;
import org.restlet.resource.Representation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* JavaMail MIME message based on an XML representation. For the XML format,
see
* the {...@link JavaMailClientHelper} class.
*
- * @author Jerome Louvel
+ * @author Jerome Louvel, Charles-henri Guérin
*/
public class RepresentationMessage extends MimeMessage {
@@ -94,11 +98,35 @@
bcc[i] = bccList.item(i).getTextContent();
}
- final String text = root.getElementsByTagName("body").item(0)
- .getTextContent();
+
+ final Element
multipart=(Element)root.getElementsByTagName("multipart").item(0);
+ final NodeList partList;
+ final MimeBodyPart[] part;
+
+ if(multipart!=null) {
+ partList=multipart.getElementsByTagName("part");
+ part=new MimeBodyPart[partList.getLength()];
+
+
+ for(int i=0;i<part.length;i++) {
+ part[i]=new MimeBodyPart();
+ Node n1=partList.item(i);
+ String
n2=n1.getAttributes().getNamedItem("type").getTextContent();
+
+ if("file".equals(n2))
+
part[i].attachFile(n1.getAttributes().getNamedItem("src").getTextContent());
+ else if("text".equals(n2) || "html".equals(n2))
{
+ String
charset=n1.getAttributes().getNamedItem("charset").getTextContent();
+
part[i].setText((String)n1.getTextContent(),charset,n2);
+ }
+ }
+ } else
+ part=null;
+
+ final Element
text=(Element)root.getElementsByTagName("body").item(0);
// Set the FROM and TO fields
- setFrom(new InternetAddress(from));
+ setHeader("From",from);
for (final String element : to) {
addRecipient(Message.RecipientType.TO, new
InternetAddress(element));
@@ -115,7 +143,23 @@
// Set the subject and content text
setSubject(subject);
- setText(text);
+
+ final MimeMultipart mp;
+ if(multipart!=null) {
+ mp=new MimeMultipart();
+
+ for(MimeBodyPart mbp:part)
+ mp.addBodyPart(mbp);
+
+ setContent(mp);
+ saveChanges();
+ } else {
+ String type=text.getAttribute("type"),
+ charset=text.getAttribute("charset");
+
+ setText(text.getTextContent(),charset,type);
+ }
+
setSentDate(new Date());
saveChanges();
}