Some more patching up of blojsom

Posted by Pepijn Oomen Thu, 30 Dec 2004 15:46:59 GMT

After yesterday's ordeal, I decided it was time to get the blojsom moblog plugin to understand IMAP. This should not be a big deal, since the JavaMail API does support IMAP pretty much the same way as it does POP3.

Initially I just replaced the pop3 static with imap and all seemed well. But then, when trying to get a picture in place, I found another strange problem. The size of the attachments was 0 bytes after storing it to disk. Was this another case of some interoperability on the Linux side?

Running the same message through the MacOSX install gave the exact same problem, so it must be something in the JavaMail API. Having discovered this, it was not difficult to find that the BodyPart.getInputStream() method for IMAP returns a estimated length of 0 bytes. The bytes are there, they just are not reported by the available() method.

More googling gave some incomplete answers, but some investigation lead to a saveFile() method that does not use available(), but just runs a byte-for-byte copy (with a buffered reader/writer, of course). That did the trick, so I can now happily create my blog entries from the familiar environment of my email client. The patch to make this possible can be dowloaded here.