From: Adam R. <ad...@ex...> - 2014-08-28 14:14:02
|
> I’ve had a look at various options for representing email messages in XML, but there’s nothing appealing. They either try to capture every little detail or skimp. > In the end, I chose to stay close to the form that is already used in the Mail Module - used by get-message-list-as-xml. The body content is stored as text and html if present, and attachments are available as base64 for storage. (I’ve successfully stored a PDF, ODT, PNG sent as attachments.) > Cool :-) > mail:get-messages($folder-handle, $message-numbers) > > There is a problem with mail:get-message-list-as-xml. > The message number is index based rather than coming from the folder: > builder.addAttribute( new QName( "number", null, null ), String.valueOf( i ) ); // where “i” is the loop index. > > this should be: > builder.addAttribute(new QName("number", null, null), String.valueOf(message.getMessageNumber())); > > This means you can’t use the message-list to choose a set of messages to retrieve. > > I think this is a bug - easily fixed - but will it cause a problem for anyone if I change it? Nope please do, but as a separate commit. > > Message example: > <mail:message xmlns:mail="http://exist-db.org/xquery/mail" number="5" contentType="multipart/mixed"> > <mail:subject>open office doc</mail:subject> > <mail:sent>2014-08-27T12:55:43.000+09:30</mail:sent> > <mail:received>2014-08-27T12:54:40.000+09:30</mail:received> > <mail:from>Alister Pillow <ali...@me...></mail:from> > <mail:recipients> > <mail:recipient type="to">in...@pe...</mail:recipient> > </mail:recipients> > <mail:text mime-type="text/plain; charset=windows-1252">Please find attached… > </mail:text> > <mail:attachment filename="test.odt" mime-type="application/vnd.oasis.opendocument.text; x-mac-type=4E4F2546; 
	x-unix-mode=0644; name=test.odt" type="binary" encoding="Base64Encoded">...</mail:attachment> > <mail:flags> > <mail:flag type="seen"/> > </mail:flags> > </mail:message> > > I want to clean up the addresses - separate the display name from the address so that the escaped < > delimiters can be removed > - and also clean up the mime-type (which is really the content-type). > > On 20 Aug 2014, at 10:41 pm, Adam Retter <ad...@ex...> wrote: > >> Hi Alister, >> >> I would stay away from having the user passing a function to handle >> the content as you don't really gain anything from that approach here. >> >> Can I suggest studying the code of eXist's httpclient module to see >> how to create XML, text or binary (base64) from external values and >> return them as nodes. >> >> Could I also suggest adopting an existing standard for representing >> email in XML if such a suitable one exists for your needs? Perhaps a >> Google for such a thing, e.g. >> http://petewarden.com/2008/10/15/an-xml-format-for-email/ >> >> On 20 August 2014 13:31, Alister Pillow <gsp...@gm...> wrote: >>> Hi all, >>> >>> I would appreciate some advice. I’m trying to write a mail:get-messages() function. >>> mail:get-messages($folder, $messageNumbers) >>> >>> I was hoping to put the contents of multipart messages (e.g. text, html, other binary forms) into an xml result (either as text, xhtml or base64binary), but I’m finding it hard to do. >>> >>> The alternative is to follow the compression:unzip approach and get the user to supply a function to handle the content. I should be able to copy the AbstractExtractFunction.processCompressedEntry method. >>> mail:get-messages($folder, $filterFunction, $storeFunction) >>> >>> Are there any downsides to that approach (other than it being harder to construct for the XQuery user)? >>> >>> …. >>> This is what I wanted to do - but can’t find simple methods of adding those content types to the XML result: >>> // for each BodyPart bp and bp.getContentType() >>> builder.startElement(new QName("body", MailModule.NAMESPACE_URI, MailModule.PREFIX), null); >>> builder.addAttribute(new QName("type", null, null), String.valueOf(contentType)); >>> >>> >>> if (contentType.contains("text/plain")) { // if TEXT store as Characters >>> builder.characters(bp.getContent().toString()); >>> } else if (contentType.contains("text/html")) { // XHTML >>> builder.?ADD?( ModuleUtils.htmlToXHtml(context, "alternative", new StreamSource(bp.getInputStream()), null, null)); >>> } else { // otherwise store as base64Binary >>> add base64 data somehow >>> } >>> builder.endElement(); >>> >>> Regards, >>> Alister >>> >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> Slashdot TV. >>> Video for Nerds. Stuff that matters. >>> http://tv.slashdot.org/ >>> _______________________________________________ >>> Exist-development mailing list >>> Exi...@li... >>> https://lists.sourceforge.net/lists/listinfo/exist-development >> >> >> >> -- >> Adam Retter >> >> eXist Developer >> { United Kingdom } >> ad...@ex... >> irc://irc.freenode.net/existdb > -- Adam Retter eXist Developer { United Kingdom } ad...@ex... irc://irc.freenode.net/existdb |