Patch Email Fix Attachments

From WebOS Internals
Jump to navigation Jump to search


Make All email attachments show up

Only in webOS 1.0.3 -- other revisions may or may not work

Introduction

You may have noticed that some of your emails with attachments do not display the attachments in the list just below the subject line. I've found the reason for this, and come up with a temporary fix for rooted Pres, which should work until Pre officially addresses this issue.

There's a minor issue with the attachment handling code of the Pre email service. If a MIME attachment is included in the body, but uses a Content-ID header. Generally, the Content-ID header allows attachments to be referenced from within an email. However, if they are not referenced, then the attachment needs to show up in the attachment list. The current email parsing code for the Pre does not do this.

Fixing It

If you'd like to fix this problem, you'll need to root your Pre, and then make an edit to a file. This is a non-trivial edit, and doing anything even slightly wrong will result in completely breaking the email app. So, as always, back everything up. Here's the procedure:

CAUTION: Unreviewed code. Proceed with caution. DO NOT BLINDLY COPY

cd /var/home/root
cp /usr/lib/luna/java/mail.jar mail.jar
cp mail.jar mail-bkup.jar
mkdir mail-fix
cd mail-fix
unzip ../mail.jar
sed -ie 's/<=/>=/g' com/palm/mail/MailService.class
/opt/bin/zip -r ../mail-fixed.jar
cd ..
mv mail-fixed.jar mail.jar
cp mail.jar /usr/lib/luna/java
pkill java

You also need to make a change in the email app itself. Find the line

if (attachments && EmailFlags.hasAttachment(this.data.flags)) {

And change it to read simply

if (attachments && attachments.length > 0) {

Technical Details

When the mail services scours the database to find messages, it also looks through attachment parts. However, database query to find attachments only matches when ContentId is NULL, or when ContentID is NOTNULL and the sizeLoaded is less than 0. I'm not sure if this is a mistake in the SQL query, or if there's a code path that uses negative size values to indicate something. I think that perhaps this query is supposed to be checking to see if the attachment has been loaded within the message body via a CID reference, but it's not working.

The small tweak to the email app is needed because the mail message will be stored with improper flags indicating whether or not it has an attachment. Changing this to behave properly is less trivial, and should really not be done using binary edits (although in theory it probably could, I will not attempt it).