2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail.internet;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2012-08-14 19:47:57 -04:00
|
|
|
import java.io.BufferedWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
2010-11-13 16:40:56 -05:00
|
|
|
|
2012-08-14 19:47:57 -04:00
|
|
|
import org.apache.james.mime4j.MimeException;
|
2011-01-19 16:32:09 -05:00
|
|
|
import org.apache.james.mime4j.dom.field.DateTimeField;
|
|
|
|
import org.apache.james.mime4j.field.DefaultFieldParser;
|
2012-08-14 19:47:57 -04:00
|
|
|
import org.apache.james.mime4j.io.EOLConvertingInputStream;
|
|
|
|
import org.apache.james.mime4j.parser.ContentHandler;
|
|
|
|
import org.apache.james.mime4j.parser.MimeStreamParser;
|
|
|
|
import org.apache.james.mime4j.stream.BodyDescriptor;
|
|
|
|
import org.apache.james.mime4j.stream.Field;
|
|
|
|
import org.apache.james.mime4j.stream.MimeConfig;
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
import org.apache.james.mime4j.util.MimeUtil;
|
2011-01-19 16:32:09 -05:00
|
|
|
|
2012-08-14 19:47:57 -04:00
|
|
|
import com.fsck.k9.mail.Address;
|
|
|
|
import com.fsck.k9.mail.Body;
|
|
|
|
import com.fsck.k9.mail.BodyPart;
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
import com.fsck.k9.mail.CompositeBody;
|
2012-08-14 19:47:57 -04:00
|
|
|
import com.fsck.k9.mail.Message;
|
|
|
|
import com.fsck.k9.mail.MessagingException;
|
|
|
|
import com.fsck.k9.mail.Multipart;
|
|
|
|
import com.fsck.k9.mail.Part;
|
|
|
|
import com.fsck.k9.mail.store.UnavailableStorageException;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An implementation of Message that stores all of it's metadata in RFC 822 and
|
|
|
|
* RFC 2045 style headers.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public class MimeMessage extends Message {
|
2008-11-01 17:32:06 -04:00
|
|
|
protected MimeHeader mHeader = new MimeHeader();
|
|
|
|
protected Address[] mFrom;
|
|
|
|
protected Address[] mTo;
|
|
|
|
protected Address[] mCc;
|
|
|
|
protected Address[] mBcc;
|
|
|
|
protected Address[] mReplyTo;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
protected String mMessageId;
|
|
|
|
protected String[] mReferences;
|
|
|
|
protected String[] mInReplyTo;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
protected Date mSentDate;
|
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
|
|
|
protected SimpleDateFormat mDateFormat;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
protected Body mBody;
|
|
|
|
protected int mSize;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public MimeMessage() {
|
2009-09-26 18:47:13 -04:00
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
|
2013-09-07 12:52:14 -04:00
|
|
|
* Nested messages will not be recursively parsed.
|
2008-11-01 17:32:06 -04:00
|
|
|
*
|
|
|
|
* @param in
|
|
|
|
* @throws IOException
|
|
|
|
* @throws MessagingException
|
2013-09-07 12:52:14 -04:00
|
|
|
*
|
|
|
|
* @see #MimeMessage(InputStream in, boolean recurse)
|
2008-11-01 17:32:06 -04:00
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public MimeMessage(InputStream in) throws IOException, MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
parse(in);
|
|
|
|
}
|
|
|
|
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
/**
|
|
|
|
* Parse the given InputStream using Apache Mime4J to build a MimeMessage.
|
|
|
|
*
|
|
|
|
* @param in
|
|
|
|
* @param recurse A boolean indicating to recurse through all nested MimeMessage subparts.
|
|
|
|
* @throws IOException
|
|
|
|
* @throws MessagingException
|
|
|
|
*/
|
|
|
|
public MimeMessage(InputStream in, boolean recurse) throws IOException, MessagingException {
|
2013-09-07 12:52:14 -04:00
|
|
|
parse(in, recurse);
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void parse(InputStream in) throws IOException, MessagingException {
|
|
|
|
parse(in, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void parse(InputStream in, boolean recurse) throws IOException, MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
mHeader.clear();
|
|
|
|
mFrom = null;
|
2009-06-15 01:04:03 -04:00
|
|
|
mTo = null;
|
|
|
|
mCc = null;
|
|
|
|
mBcc = null;
|
|
|
|
mReplyTo = null;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
mMessageId = null;
|
|
|
|
mReferences = null;
|
|
|
|
mInReplyTo = null;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
mSentDate = null;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-06-15 01:04:03 -04:00
|
|
|
mBody = null;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2012-08-14 19:47:57 -04:00
|
|
|
MimeConfig parserConfig = new MimeConfig();
|
2011-02-01 15:48:20 -05:00
|
|
|
parserConfig.setMaxHeaderLen(-1); // The default is a mere 10k
|
|
|
|
parserConfig.setMaxLineLen(-1); // The default is 1000 characters. Some MUAs generate
|
2011-02-06 17:09:48 -05:00
|
|
|
// REALLY long References: headers
|
2011-07-02 17:52:54 -04:00
|
|
|
parserConfig.setMaxHeaderCount(-1); // Disable the check for header count.
|
2011-02-01 15:48:20 -05:00
|
|
|
MimeStreamParser parser = new MimeStreamParser(parserConfig);
|
2008-11-01 17:32:06 -04:00
|
|
|
parser.setContentHandler(new MimeMessageBuilder());
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
if (recurse) {
|
|
|
|
parser.setRecurse();
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2011-01-19 16:32:09 -05:00
|
|
|
parser.parse(new EOLConvertingInputStream(in));
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MimeException me) {
|
2011-01-19 16:33:23 -05:00
|
|
|
throw new Error(me);
|
2011-01-19 16:32:09 -05:00
|
|
|
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Date getSentDate() {
|
|
|
|
if (mSentDate == null) {
|
|
|
|
try {
|
2011-01-19 16:32:09 -05:00
|
|
|
DateTimeField field = (DateTimeField)DefaultFieldParser.parse("Date: "
|
2009-11-24 19:40:29 -05:00
|
|
|
+ MimeUtility.unfoldAndDecode(getFirstHeader("Date")));
|
2008-11-01 17:32:06 -04:00
|
|
|
mSentDate = field.getDate();
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (Exception e) {
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mSentDate;
|
|
|
|
}
|
|
|
|
|
2009-09-25 15:12:37 -04:00
|
|
|
/**
|
|
|
|
* Sets the sent date object member as well as *adds* the 'Date' header
|
|
|
|
* instead of setting it (for performance reasons).
|
|
|
|
*
|
|
|
|
* @see #mSentDate
|
|
|
|
* @param sentDate
|
2009-12-14 21:50:53 -05:00
|
|
|
* @throws com.fsck.k9.mail.MessagingException
|
2009-09-25 15:12:37 -04:00
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public void addSentDate(Date sentDate) throws MessagingException {
|
|
|
|
if (mDateFormat == null) {
|
2009-09-25 15:12:37 -04:00
|
|
|
mDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
|
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
|
|
|
}
|
2009-09-25 15:12:37 -04:00
|
|
|
addHeader("Date", mDateFormat.format(sentDate));
|
r62972@17h: jesse | 2009-05-07 10:49:32 -0400
First stab at a folderlist that doesn't know or care about messages
r62973@17h: jesse | 2009-05-07 10:50:11 -0400
A very broken first stab at a message list that only knows about one folder.
r62974@17h: jesse | 2009-05-07 10:50:44 -0400
When you go from an account list to an individual account, open a folderlist, not an fml
r62975@17h: jesse | 2009-05-07 10:51:24 -0400
Update Welcome activity to open an ml instead of an fml
r62976@17h: jesse | 2009-05-07 10:51:59 -0400
When setting up accounts is over, open an fl instead of an fml
r62977@17h: jesse | 2009-05-07 10:52:51 -0400
Update MessageView to use folderinfoholders and messageinfoholders from the 'correct' classes.
r62978@17h: jesse | 2009-05-07 10:59:07 -0400
MailService now notifies the fl instead of the fml. Not sure if it should also notify the ml. - will require testing
r62979@17h: jesse | 2009-05-07 11:01:09 -0400
Switch MessagingController's notifications from notifying the FML to notifying an ML
r62980@17h: jesse | 2009-05-07 11:25:22 -0400
Update AndroidManifest to know about the new world order
r62981@17h: jesse | 2009-05-07 11:26:11 -0400
Try to follow the android sdk docs for intent creation
r62982@17h: jesse | 2009-05-07 11:28:30 -0400
reset MessageList for another try at the conversion
r62983@17h: jesse | 2009-05-07 11:47:33 -0400
This version doesn't crash and has a working 'folder' layer. now to clean up the message list layer
r62984@17h: jesse | 2009-05-07 15:18:04 -0400
move step 1
r62985@17h: jesse | 2009-05-07 15:18:37 -0400
move step 1
r62986@17h: jesse | 2009-05-07 15:22:47 -0400
rename step 1
r62987@17h: jesse | 2009-05-07 17:38:02 -0400
checkpoint to move
r62988@17h: jesse | 2009-05-07 17:40:01 -0400
checkpointing a state with a working folder list and a message list that doesn't explode
r62989@17h: jesse | 2009-05-07 17:40:26 -0400
Remove debugging cruft from Welcome
r62990@17h: jesse | 2009-05-07 22:00:12 -0400
Basic functionality works.
r62991@17h: jesse | 2009-05-08 04:19:52 -0400
added a tool to build a K-9 "Beta"
r62992@17h: jesse | 2009-05-08 04:20:03 -0400
remove a disused file
r62993@17h: jesse | 2009-05-09 06:07:02 -0400
upgrading build infrastructure for the 1.5 sdk
r62994@17h: jesse | 2009-05-09 06:22:02 -0400
further refine onOpenMessage, removing more folder assumptions
r62995@17h: jesse | 2009-05-09 20:07:20 -0400
Make the Welcome activity open the autoexpandfolder rather than INBOX
r62996@17h: jesse | 2009-05-09 20:14:10 -0400
MessageList now stores the Folder name it was working with across pause-reload
r62997@17h: jesse | 2009-05-09 20:14:26 -0400
Removing dead code from FolderList
r63060@17h: jesse | 2009-05-10 00:07:33 -0400
Replace the old message list refreshing code which cleared and rebuilt the list from scratch with code which updates or deletes existing messages.
Add "go back to folder list" code
r63061@17h: jesse | 2009-05-10 00:07:50 -0400
fix message list menus for new world order
r63062@17h: jesse | 2009-05-10 00:08:11 -0400
Remove message list options from folder list menus
r63063@17h: jesse | 2009-05-10 00:10:02 -0400
remove more message list options from the folder list
r63064@17h: jesse | 2009-05-10 00:10:19 -0400
fix build.xml for the new android world order
r63065@17h: jesse | 2009-05-10 00:39:23 -0400
reformatted in advance of bug tracing
r63066@17h: jesse | 2009-05-10 05:53:28 -0400
fix our 'close' behavior to not leave extra activities around
clean up more vestigal code
r63067@17h: jesse | 2009-05-10 18:44:25 -0400
Improve "back button / accounts" workflow from FolderList -> AccountList
r63068@17h: jesse | 2009-05-10 19:11:47 -0400
* Add required code for the 'k9beta' build
r63069@17h: jesse | 2009-05-10 19:12:05 -0400
Make the folder list white backgrounded.
r63070@17h: jesse | 2009-05-10 19:12:26 -0400
* Include our required libraries in build.xml
r63071@17h: jesse | 2009-05-10 19:13:07 -0400
Added directories for our built code and our generated code
r63072@17h: jesse | 2009-05-10 19:13:36 -0400
Added a "back" button image
r63073@17h: jesse | 2009-05-10 20:13:50 -0400
Switch next/prev buttons to triangles for I18N and eventual "more easy-to-hit buttons" win
r63074@17h: jesse | 2009-05-10 20:17:18 -0400
Tidy Accounts.java for some perf hacking.
r63081@17h: jesse | 2009-05-10 22:13:33 -0400
First pass reformatting of the MessagingController
r63082@17h: jesse | 2009-05-10 23:50:28 -0400
MessageList now correctly updates when a background sync happens
r63083@17h: jesse | 2009-05-10 23:50:53 -0400
Tidying FolderList
r63084@17h: jesse | 2009-05-10 23:51:09 -0400
tidy
r63085@17h: jesse | 2009-05-10 23:51:27 -0400
tidy
r63086@17h: jesse | 2009-05-11 00:17:06 -0400
Properly update unread counts in the FolderList after sync
r63087@17h: jesse | 2009-05-11 01:38:14 -0400
Minor refactoring for readability. replace a boolean with a constant.
r63090@17h: jesse | 2009-05-11 02:58:31 -0400
now that the foreground of message lists is light, we don't need the light messagebox
r63091@17h: jesse | 2009-05-11 17:15:02 -0400
Added a string for "back to folder list"
r63092@17h: jesse | 2009-05-11 17:15:24 -0400
Added a message list header with a back button
r63093@17h: jesse | 2009-05-11 17:15:54 -0400
Remove the "folder list" button from the options menu. no sense duplicating it
r63094@17h: jesse | 2009-05-11 17:17:06 -0400
Refactored views, adding our replacement scrollable header
r63184@17h: jesse | 2009-05-12 07:07:15 -0400
fix weird bug where message lists could show a header element for a child
r63185@17h: jesse | 2009-05-12 07:08:12 -0400
Add new-style headers to folder lists. reimplement "get folder by name" to not use a bloody for loop
r63211@17h: jesse | 2009-05-12 18:37:48 -0400
Restore the former glory of the "load more messages" widget. it still needs an overhaul
r63296@17h: jesse | 2009-05-12 23:23:21 -0400
Get the indeterminate progress bar to show up again when you click "get more messages"
r63297@17h: jesse | 2009-05-13 02:40:39 -0400
Fixed off-by-one errors in click and keybindings for messagelist
r63298@17h: jesse | 2009-05-13 06:04:01 -0400
Put the folder title in the name of the folderSettings popup
r63299@17h: jesse | 2009-05-13 06:04:49 -0400
Reformatting. Removing debug logging
r63300@17h: jesse | 2009-05-13 06:05:32 -0400
Fixing "wrong item selected" bugs in the FolderList
r63328@17h: jesse | 2009-05-13 13:20:00 -0400
Update MessageView for 1.5
r63329@17h: jesse | 2009-05-13 13:50:29 -0400
A couple fixes to "picking the right item"
Titles on the message context menu
r63330@17h: jesse | 2009-05-13 13:58:37 -0400
Added an "open" context menu item to the folder list
r63347@17h: jesse | 2009-05-13 18:00:02 -0400
Try to get folderlists to sort in a stable way, so they jump around less in the ui
r63349@17h: jesse | 2009-05-13 20:37:19 -0400
Switch to using non-message-passing based notifications for redisplay of message lists, cut down redisplay frequency to not overload the display
r63432@17h: jesse | 2009-05-16 13:38:49 -0400
Android 1.5 no longer gives us apache.commons.codec by default and apache.commons.logging by default. Import them so we have em.
There's probably something smarter to do here.
r63438@17h: jesse | 2009-05-16 14:12:06 -0400
removed dead code
r63439@17h: jesse | 2009-05-16 14:30:57 -0400
Minor tidy
r63440@17h: jesse | 2009-05-16 14:39:34 -0400
First pass implementation making MessageList streamy for faster startup
r63441@17h: jesse | 2009-05-16 21:57:41 -0400
There's no reason for the FolderList to list local messages
r63442@17h: jesse | 2009-05-16 21:58:57 -0400
Switch to actually refreshing the message list after each item is loaded
r63450@17h: jesse | 2009-05-16 22:34:18 -0400
Default to pulling items out of the LocalStore by date, descending. (since that's the uneditable default ordering)
This makes our messages come out of the store in the order the user should see them
r63451@17h: jesse | 2009-05-16 22:34:44 -0400
Set some new defaults for the FolderList
r63452@17h: jesse | 2009-05-16 22:35:43 -0400
set some new message list item defaults
r63456@17h: jesse | 2009-05-17 12:56:10 -0400
It's not clear that Pop and WebDav actually set us an InternalDate. I'd rather use that so that spam doesn't topsort. But I also want this to _work_
r63457@17h: jesse | 2009-05-17 12:56:47 -0400
actually check to make sure we have a message to remove before removing it.
r63458@17h: jesse | 2009-05-17 13:10:07 -0400
Flip "security type" to before the port number, since changing security type is the thing more users are likely to know/care about and resets port number
r63469@17h: jesse | 2009-05-17 18:42:39 -0400
Provisional fix for "see the FoldeRList twice" bug
r63471@17h: jesse | 2009-05-17 20:47:41 -0400
Remove title bar from the message view
r63544@17h: jesse | 2009-05-20 23:53:38 -0400
folderlist tidying before i dig into the jumpy ordering bug
r63545@17h: jesse | 2009-05-20 23:56:00 -0400
Killing dead variables
r63546@17h: jesse | 2009-05-21 00:58:36 -0400
make the whole title section clicky
r63556@17h: jesse | 2009-05-21 01:48:13 -0400
Fix where we go when someone deletes a message
r63558@17h: jesse | 2009-05-21 22:44:46 -0400
Working toward switchable themes
r63563@17h: jesse | 2009-05-21 23:53:09 -0400
Make the MessageList's colors actually just inherit from the theme, rather than hardcoding black
r63567@17h: jesse | 2009-05-22 10:14:13 -0400
Kill a now-redundant comment
r63571@17h: jesse | 2009-05-22 19:43:30 -0400
further theme-independence work
r63572@17h: jesse | 2009-05-22 19:55:23 -0400
gete -> get (typo fix)
r63573@17h: jesse | 2009-05-22 22:48:49 -0400
First cut of a global prefs system as well as a theme preference. not that it works yet
r63577@17h: jesse | 2009-05-24 14:49:52 -0400
Once a user has actually put in valid user credentials, start syncing mail and folders in the background instantly.
This gives us a much better "new startup" experience
r63578@17h: jesse | 2009-05-24 14:55:00 -0400
MessageList doesn't need FolderUpdateWorker
r63579@17h: jesse | 2009-05-24 17:57:15 -0400
Fix "get message by uid"
Switch to showing messages 10 by 10, rather than 1 by 1 for huge loadtime performance improvements
r63587@17h: jesse | 2009-05-24 19:19:56 -0400
Cut down LocalMessage creation to not generate a MessageId or date formatter.
r63589@17h: jesse | 2009-05-24 22:22:32 -0400
Switch to null-escaping email address boundaries, rather than a VERY expensive URL-encoding
r63590@17h: jesse | 2009-05-24 22:23:21 -0400
Clean up our "auto-refresh the list when adding messages after a sync"
r63593@17h: jesse | 2009-05-24 22:53:45 -0400
replace isDateToday with a "rolling 18 hour window" variant that's more likely to give the user a useful answer and is 30x faster.
r63595@17h: jesse | 2009-05-24 23:54:14 -0400
When instantiating messges from the LocalStore, there's no need to clear headers before setting them, nor is there a need to set a generated message id
r63596@17h: jesse | 2009-05-24 23:54:39 -0400
make an overridable setGeneratedMessageId
r63597@17h: jesse | 2009-05-24 23:54:55 -0400
Remove new lies from comments
r63598@17h: jesse | 2009-05-24 23:55:35 -0400
Replace insanely expensive message header "name" part quoting with something consistent and cheap that does its work on the way INTO the database
r63605@17h: jesse | 2009-05-25 17:28:24 -0400
bring back the 1.1 sdk build.xml
r63606@17h: jesse | 2009-05-25 22:32:11 -0400
Actually enable switchable themese and compilation on 1.1
r63692@17h: jesse | 2009-05-29 23:55:17 -0400
Switch back to having titles for folder and message lists.
Restore auto-open-folder functionality
r63694@17h: jesse | 2009-05-30 18:50:39 -0400
Remove several off-by-one errors introduced by yesterday's return to android titlebars
r63696@17h: jesse | 2009-05-30 23:45:03 -0400
use convertView properly for performance and memory imrpovement in FolderList and MessageList
r63698@17h: jesse | 2009-05-31 19:42:59 -0400
Switch to using background shading to indicate "not yet fetched"
r63701@17h: jesse | 2009-05-31 21:28:47 -0400
Remving code we don't actually need these bits of apache commons on 1.1
2009-05-31 21:35:05 -04:00
|
|
|
setInternalSentDate(sentDate);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setSentDate(Date sentDate) throws MessagingException {
|
2009-09-25 15:12:37 -04:00
|
|
|
removeHeader("Date");
|
|
|
|
addSentDate(sentDate);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setInternalSentDate(Date sentDate) {
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mSentDate = sentDate;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getContentType() throws MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
String contentType = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
|
2013-09-02 18:43:51 -04:00
|
|
|
return (contentType == null) ? "text/plain" : contentType;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getDisposition() throws MessagingException {
|
2011-06-16 22:13:32 -04:00
|
|
|
return getFirstHeader(MimeHeader.HEADER_CONTENT_DISPOSITION);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getContentId() throws MessagingException {
|
2010-07-11 09:44:16 -04:00
|
|
|
return null;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getMimeType() throws MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
return MimeUtility.getHeaderParameter(getContentType(), null);
|
|
|
|
}
|
|
|
|
|
2013-09-02 18:43:51 -04:00
|
|
|
public boolean isMimeType(String mimeType) throws MessagingException {
|
|
|
|
return getMimeType().equalsIgnoreCase(mimeType);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public int getSize() {
|
2008-11-01 17:32:06 -04:00
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of the given recipient type from this message. If no addresses are
|
|
|
|
* found the method returns an empty array.
|
|
|
|
*/
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Address[] getRecipients(RecipientType type) throws MessagingException {
|
|
|
|
if (type == RecipientType.TO) {
|
|
|
|
if (mTo == null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
mTo = Address.parse(MimeUtility.unfold(getFirstHeader("To")));
|
|
|
|
}
|
|
|
|
return mTo;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (type == RecipientType.CC) {
|
|
|
|
if (mCc == null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
mCc = Address.parse(MimeUtility.unfold(getFirstHeader("CC")));
|
|
|
|
}
|
|
|
|
return mCc;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (type == RecipientType.BCC) {
|
|
|
|
if (mBcc == null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
mBcc = Address.parse(MimeUtility.unfold(getFirstHeader("BCC")));
|
|
|
|
}
|
|
|
|
return mBcc;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unrecognized recipient type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setRecipients(RecipientType type, Address[] addresses) throws MessagingException {
|
|
|
|
if (type == RecipientType.TO) {
|
|
|
|
if (addresses == null || addresses.length == 0) {
|
2008-11-01 17:32:06 -04:00
|
|
|
removeHeader("To");
|
|
|
|
this.mTo = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2009-09-10 13:33:19 -04:00
|
|
|
setHeader("To", Address.toEncodedString(addresses));
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mTo = addresses;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (type == RecipientType.CC) {
|
|
|
|
if (addresses == null || addresses.length == 0) {
|
2008-11-01 17:32:06 -04:00
|
|
|
removeHeader("CC");
|
|
|
|
this.mCc = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2009-09-10 13:33:19 -04:00
|
|
|
setHeader("CC", Address.toEncodedString(addresses));
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mCc = addresses;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (type == RecipientType.BCC) {
|
|
|
|
if (addresses == null || addresses.length == 0) {
|
2008-11-01 17:32:06 -04:00
|
|
|
removeHeader("BCC");
|
|
|
|
this.mBcc = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2009-09-10 13:33:19 -04:00
|
|
|
setHeader("BCC", Address.toEncodedString(addresses));
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mBcc = addresses;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unrecognized recipient type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the unfolded, decoded value of the Subject header.
|
|
|
|
*/
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getSubject() {
|
2011-01-13 19:53:19 -05:00
|
|
|
return MimeUtility.unfoldAndDecode(getFirstHeader("Subject"), this);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setSubject(String subject) throws MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
setHeader("Subject", subject);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Address[] getFrom() {
|
|
|
|
if (mFrom == null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
String list = MimeUtility.unfold(getFirstHeader("From"));
|
2011-02-06 17:09:48 -05:00
|
|
|
if (list == null || list.length() == 0) {
|
2008-11-01 17:32:06 -04:00
|
|
|
list = MimeUtility.unfold(getFirstHeader("Sender"));
|
|
|
|
}
|
|
|
|
mFrom = Address.parse(list);
|
|
|
|
}
|
|
|
|
return mFrom;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setFrom(Address from) throws MessagingException {
|
|
|
|
if (from != null) {
|
2009-09-10 13:33:19 -04:00
|
|
|
setHeader("From", from.toEncodedString());
|
2011-02-06 17:09:48 -05:00
|
|
|
this.mFrom = new Address[] {
|
2009-11-24 19:40:29 -05:00
|
|
|
from
|
|
|
|
};
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mFrom = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Address[] getReplyTo() {
|
|
|
|
if (mReplyTo == null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
mReplyTo = Address.parse(MimeUtility.unfold(getFirstHeader("Reply-to")));
|
|
|
|
}
|
|
|
|
return mReplyTo;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setReplyTo(Address[] replyTo) throws MessagingException {
|
|
|
|
if (replyTo == null || replyTo.length == 0) {
|
2008-11-01 17:32:06 -04:00
|
|
|
removeHeader("Reply-to");
|
|
|
|
mReplyTo = null;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2009-09-10 13:33:19 -04:00
|
|
|
setHeader("Reply-to", Address.toEncodedString(replyTo));
|
2008-11-01 17:32:06 -04:00
|
|
|
mReplyTo = replyTo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public String getMessageId() throws MessagingException {
|
|
|
|
if (mMessageId == null) {
|
2009-11-24 19:40:29 -05:00
|
|
|
mMessageId = getFirstHeader("Message-ID");
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mMessageId == null) { // even after checking the header
|
2009-12-07 23:58:10 -05:00
|
|
|
setMessageId(generateMessageId());
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
return mMessageId;
|
2009-11-17 16:13:29 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private String generateMessageId() {
|
|
|
|
return "<" + UUID.randomUUID().toString() + "@email.android.com>";
|
2009-12-07 23:58:10 -05:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setMessageId(String messageId) throws UnavailableStorageException {
|
2009-12-06 23:46:36 -05:00
|
|
|
setHeader("Message-ID", messageId);
|
|
|
|
mMessageId = messageId;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setInReplyTo(String inReplyTo) throws MessagingException {
|
2009-11-24 19:40:29 -05:00
|
|
|
setHeader("In-Reply-To", inReplyTo);
|
2009-11-17 16:13:29 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public String[] getReferences() throws MessagingException {
|
|
|
|
if (mReferences == null) {
|
2009-11-24 19:40:29 -05:00
|
|
|
mReferences = getHeader("References");
|
|
|
|
}
|
|
|
|
return mReferences;
|
2009-11-17 16:13:29 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setReferences(String references) throws MessagingException {
|
2010-05-21 08:20:32 -04:00
|
|
|
/*
|
2010-05-21 12:37:45 -04:00
|
|
|
* Make sure the References header doesn't exceed the maximum header
|
|
|
|
* line length and won't get (Q-)encoded later. Otherwise some clients
|
|
|
|
* will break threads apart.
|
|
|
|
*
|
2010-05-21 08:20:32 -04:00
|
|
|
* For more information see issue 1559.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Make sure separator is SPACE to prevent Q-encoding when TAB is encountered
|
|
|
|
references = references.replaceAll("\\s+", " ");
|
|
|
|
|
2010-05-21 12:37:45 -04:00
|
|
|
/*
|
|
|
|
* NOTE: Usually the maximum header line is 998 + CRLF = 1000 characters.
|
|
|
|
* But at least one implementations seems to have problems with 998
|
|
|
|
* characters, so we adjust for that fact.
|
|
|
|
*/
|
2010-05-30 00:17:00 -04:00
|
|
|
final int limit = 1000 - 2 /* CRLF */ - 12 /* "References: " */ - 1 /* Off-by-one bugs */;
|
2010-05-21 08:20:32 -04:00
|
|
|
final int originalLength = references.length();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (originalLength >= limit) {
|
2010-05-30 00:17:00 -04:00
|
|
|
// Find start of first reference
|
|
|
|
final int start = references.indexOf('<');
|
2010-05-21 08:20:32 -04:00
|
|
|
|
2010-05-30 00:17:00 -04:00
|
|
|
// First reference + SPACE
|
2010-05-21 08:20:32 -04:00
|
|
|
final String firstReference = references.substring(start,
|
2010-05-30 00:17:00 -04:00
|
|
|
references.indexOf('<', start + 1));
|
2010-05-21 08:20:32 -04:00
|
|
|
|
|
|
|
// Find longest tail
|
|
|
|
final String tail = references.substring(references.indexOf('<',
|
2010-05-30 00:17:00 -04:00
|
|
|
firstReference.length() + originalLength - limit));
|
2010-05-21 08:20:32 -04:00
|
|
|
|
|
|
|
references = firstReference + tail;
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
setHeader("References", references);
|
2009-11-17 16:13:29 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Body getBody() {
|
2008-11-01 17:32:06 -04:00
|
|
|
return mBody;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setBody(Body body) throws MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mBody = body;
|
2010-02-04 12:28:35 -05:00
|
|
|
setHeader("MIME-Version", "1.0");
|
2011-02-06 17:09:48 -05:00
|
|
|
if (body instanceof Multipart) {
|
2010-02-04 18:37:50 -05:00
|
|
|
Multipart multipart = ((Multipart)body);
|
2008-11-01 17:32:06 -04:00
|
|
|
multipart.setParent(this);
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
String type = multipart.getContentType();
|
|
|
|
setHeader(MimeHeader.HEADER_CONTENT_TYPE, type);
|
|
|
|
if ("multipart/signed".equalsIgnoreCase(type)) {
|
|
|
|
setEncoding(MimeUtil.ENC_7BIT);
|
|
|
|
} else {
|
|
|
|
setEncoding(MimeUtil.ENC_8BIT);
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (body instanceof TextBody) {
|
2013-09-02 19:56:59 -04:00
|
|
|
setHeader(MimeHeader.HEADER_CONTENT_TYPE, String.format("%s;\r\n charset=utf-8",
|
2009-11-24 19:40:29 -05:00
|
|
|
getMimeType()));
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
setEncoding(MimeUtil.ENC_8BIT);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
protected String getFirstHeader(String name) {
|
2008-11-01 17:32:06 -04:00
|
|
|
return mHeader.getFirstHeader(name);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void addHeader(String name, String value) throws UnavailableStorageException {
|
2008-11-01 17:32:06 -04:00
|
|
|
mHeader.addHeader(name, value);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setHeader(String name, String value) throws UnavailableStorageException {
|
2008-11-01 17:32:06 -04:00
|
|
|
mHeader.setHeader(name, value);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public String[] getHeader(String name) throws UnavailableStorageException {
|
2008-11-01 17:32:06 -04:00
|
|
|
return mHeader.getHeader(name);
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void removeHeader(String name) throws UnavailableStorageException {
|
2008-11-01 17:32:06 -04:00
|
|
|
mHeader.removeHeader(name);
|
|
|
|
}
|
|
|
|
|
2010-05-21 11:34:29 -04:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public Set<String> getHeaderNames() throws UnavailableStorageException {
|
2009-06-08 23:11:35 -04:00
|
|
|
return mHeader.getHeaderNames();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
2009-12-07 23:58:10 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);
|
|
|
|
mHeader.writeTo(out);
|
|
|
|
writer.write("\r\n");
|
|
|
|
writer.flush();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mBody != null) {
|
2008-11-01 17:32:06 -04:00
|
|
|
mBody.writeTo(out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public InputStream getInputStream() throws MessagingException {
|
2008-11-01 17:32:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-04-16 08:20:10 -04:00
|
|
|
@Override
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
public void setEncoding(String encoding) throws MessagingException {
|
|
|
|
if (mBody != null) {
|
|
|
|
mBody.setEncoding(encoding);
|
2010-02-04 18:37:50 -05:00
|
|
|
}
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
|
2010-02-04 18:37:50 -05:00
|
|
|
}
|
|
|
|
|
2011-01-18 18:54:49 -05:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setCharset(String charset) throws MessagingException {
|
2010-12-23 04:58:13 -05:00
|
|
|
mHeader.setCharset(charset);
|
2011-02-06 17:09:48 -05:00
|
|
|
if (mBody instanceof Multipart) {
|
2011-01-04 08:25:59 -05:00
|
|
|
((Multipart)mBody).setCharset(charset);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (mBody instanceof TextBody) {
|
2011-01-04 08:25:59 -05:00
|
|
|
MimeUtility.setCharset(charset, this);
|
|
|
|
((TextBody)mBody).setCharset(charset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
class MimeMessageBuilder implements ContentHandler {
|
2011-11-02 23:47:48 -04:00
|
|
|
private final LinkedList<Object> stack = new LinkedList<Object>();
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public MimeMessageBuilder() {
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void expect(Class<?> c) {
|
2011-11-02 23:47:48 -04:00
|
|
|
if (!c.isInstance(stack.peek())) {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new IllegalStateException("Internal stack error: " + "Expected '"
|
2009-11-24 19:40:29 -05:00
|
|
|
+ c.getName() + "' found '" + stack.peek().getClass().getName() + "'");
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void startMessage() {
|
|
|
|
if (stack.isEmpty()) {
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.addFirst(MimeMessage.this);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(Part.class);
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2008-11-01 17:32:06 -04:00
|
|
|
MimeMessage m = new MimeMessage();
|
2011-11-02 23:47:48 -04:00
|
|
|
((Part)stack.peek()).setBody(m);
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.addFirst(m);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException me) {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new Error(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void endMessage() {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(MimeMessage.class);
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.removeFirst();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void startHeader() {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(Part.class);
|
|
|
|
}
|
|
|
|
|
2011-01-19 16:32:09 -05:00
|
|
|
|
2012-08-14 19:47:57 -04:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void endHeader() {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(Part.class);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void startMultipart(BodyDescriptor bd) {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(Part.class);
|
|
|
|
|
2011-11-02 23:47:48 -04:00
|
|
|
Part e = (Part)stack.peek();
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2008-11-01 17:32:06 -04:00
|
|
|
MimeMultipart multiPart = new MimeMultipart(e.getContentType());
|
|
|
|
e.setBody(multiPart);
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.addFirst(multiPart);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException me) {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new Error(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void body(BodyDescriptor bd, InputStream in) throws IOException {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(Part.class);
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
Body body = MimeUtility.decodeBody(in,
|
|
|
|
bd.getTransferEncoding(), bd.getMimeType());
|
2011-11-02 23:47:48 -04:00
|
|
|
((Part)stack.peek()).setBody(body);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException me) {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new Error(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void endMultipart() {
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.removeFirst();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void startBodyPart() {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(MimeMultipart.class);
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
try {
|
2008-11-01 17:32:06 -04:00
|
|
|
MimeBodyPart bodyPart = new MimeBodyPart();
|
2011-11-02 23:47:48 -04:00
|
|
|
((MimeMultipart)stack.peek()).addBodyPart(bodyPart);
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.addFirst(bodyPart);
|
2011-02-06 17:09:48 -05:00
|
|
|
} catch (MessagingException me) {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new Error(me);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void endBodyPart() {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(BodyPart.class);
|
2011-09-30 02:22:44 -04:00
|
|
|
stack.removeFirst();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void epilogue(InputStream is) throws IOException {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(MimeMultipart.class);
|
2011-09-30 02:18:00 -04:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2008-11-01 17:32:06 -04:00
|
|
|
int b;
|
2011-02-06 17:09:48 -05:00
|
|
|
while ((b = is.read()) != -1) {
|
2008-11-01 17:32:06 -04:00
|
|
|
sb.append((char)b);
|
|
|
|
}
|
2011-11-02 23:47:48 -04:00
|
|
|
// ((Multipart) stack.peek()).setEpilogue(sb.toString());
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void preamble(InputStream is) throws IOException {
|
2008-11-01 17:32:06 -04:00
|
|
|
expect(MimeMultipart.class);
|
2011-09-30 02:18:00 -04:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2008-11-01 17:32:06 -04:00
|
|
|
int b;
|
2011-02-06 17:09:48 -05:00
|
|
|
while ((b = is.read()) != -1) {
|
2008-11-01 17:32:06 -04:00
|
|
|
sb.append((char)b);
|
|
|
|
}
|
2011-11-02 23:47:48 -04:00
|
|
|
((MimeMultipart)stack.peek()).setPreamble(sb.toString());
|
2010-11-30 22:02:13 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void raw(InputStream is) throws IOException {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new UnsupportedOperationException("Not supported");
|
|
|
|
}
|
2012-08-14 19:47:57 -04:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void field(Field parsedField) throws MimeException {
|
|
|
|
expect(Part.class);
|
|
|
|
try {
|
|
|
|
((Part)stack.peek()).addHeader(parsedField.getName(), parsedField.getBody().trim());
|
|
|
|
} catch (MessagingException me) {
|
|
|
|
throw new Error(me);
|
|
|
|
}
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2012-01-03 20:27:51 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy the contents of this object into another {@code MimeMessage} object.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* The {@code MimeMessage} object to receive the contents of this instance.
|
|
|
|
*/
|
|
|
|
protected void copy(MimeMessage message) {
|
|
|
|
super.copy(message);
|
|
|
|
|
|
|
|
message.mHeader = mHeader.clone();
|
|
|
|
|
|
|
|
message.mBody = mBody;
|
|
|
|
message.mMessageId = mMessageId;
|
|
|
|
message.mSentDate = mSentDate;
|
|
|
|
message.mDateFormat = mDateFormat;
|
|
|
|
message.mSize = mSize;
|
|
|
|
|
|
|
|
// These arrays are not supposed to be modified, so it's okay to reuse the references
|
|
|
|
message.mFrom = mFrom;
|
|
|
|
message.mTo = mTo;
|
|
|
|
message.mCc = mCc;
|
|
|
|
message.mBcc = mBcc;
|
|
|
|
message.mReplyTo = mReplyTo;
|
|
|
|
message.mReferences = mReferences;
|
|
|
|
message.mInReplyTo = mInReplyTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public MimeMessage clone() {
|
|
|
|
MimeMessage message = new MimeMessage();
|
|
|
|
copy(message);
|
|
|
|
return message;
|
|
|
|
}
|
2012-03-05 15:04:34 -05:00
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
return Long.parseLong(mUid); //or maybe .mMessageId?
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPreview() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasAttachments() {
|
|
|
|
return false;
|
|
|
|
}
|
Recursively convert attachments of type message/rfc822 to 7bit if necessary.
The preceding commit resulted in attachments of type message/rfc822 being
sent with 8bit encoding even when the SMTP server did not support
8BITMIME. This commit assures that messages will be converted to 7bit
when necessary.
A new interface CompositeBody was created that extends Body, and classes
Message and Multipart were changed from implementing Body to
CompositeBody. Additional classes BinaryTempFileMessageBody and
LocalAttachmentMessageBody were created (by extending BinaryTempFileBody
and LocalAttachmentBody, respectively), and they too implement
CompositeBody.
A CompositeBody is a Body containing a composite-type that can contain
subparts that may require recursive processing when converting from 8bit
to 7bit. The Part to which a CompositeBody belongs is only permitted to
use 8bit or 7bit encoding for the CompositeBody.
Previously, a Message was created so that it was 7bit clean by default
(even though that meant base64 encoding all attachments, including
messages). Then, if the SMTP server supported 8BITMIME,
Message.setEncoding("8bit") was called so that bodies of type TextBody
would been transmitted using 8bit encoding rather than quoted-printable.
Now, messages are created with 8bit encoding by default. Then, if the
SMTP server does not support 8BITMIME, Message.setUsing7bitTransport is
called to recursively convert the message and its subparts to 7bit. The
method setUsing7bitTransport was added to the interfaces Part and
CompositeBody.
setEncoding no longer iterates over parts in Multipart. That task belongs
to setUsing7bitTransport, which may in turn call setEncoding on the parts.
MimeUtility.getEncodingforType was created as a helper function for
choosing a default encoding that should be used for a given MIME type when
an attachment is added to a message (either while composing or when
retrieving from LocalStore).
setEncoding was implemented in MimeBodyPart to assure that the encoding
set in the Part's headers was the same as set for the Part's Body. (The
method already existed in MimeMessage, which has similarities with
MimeBodyPart.)
MimeMessage.parse(InputStream in, boolean recurse) was implemented so that
the parser could be told to recursively process nested messages read from
the InputStream, thus giving access to all subparts at any level that may
need to be converted from 8bit to 7bit.
2013-09-02 23:49:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setUsing7bitTransport() throws MessagingException {
|
|
|
|
String type = getFirstHeader(MimeHeader.HEADER_CONTENT_TYPE);
|
|
|
|
/*
|
|
|
|
* We don't trust that a multipart/* will properly have an 8bit encoding
|
|
|
|
* header if any of its subparts are 8bit, so we automatically recurse
|
|
|
|
* (as long as its not multipart/signed).
|
|
|
|
*/
|
|
|
|
if (mBody instanceof CompositeBody
|
|
|
|
&& !"multipart/signed".equalsIgnoreCase(type)) {
|
|
|
|
setEncoding(MimeUtil.ENC_7BIT);
|
|
|
|
// recurse
|
|
|
|
((CompositeBody) mBody).setUsing7bitTransport();
|
|
|
|
} else if (!MimeUtil.ENC_8BIT
|
|
|
|
.equalsIgnoreCase(getFirstHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING))) {
|
|
|
|
return;
|
|
|
|
} else if (type != null
|
|
|
|
&& (type.equalsIgnoreCase("multipart/signed") || type
|
|
|
|
.toLowerCase(Locale.US).startsWith("message/"))) {
|
|
|
|
/*
|
|
|
|
* This shouldn't happen. In any case, it would be wrong to convert
|
|
|
|
* them to some other encoding for 7bit transport.
|
|
|
|
*
|
|
|
|
* RFC 1847 says multipart/signed must be 7bit. It also says their
|
|
|
|
* bodies must be treated as opaque, so we must not change the
|
|
|
|
* encoding.
|
|
|
|
*
|
|
|
|
* We've dealt with (CompositeBody) type message/rfc822 above. Here
|
|
|
|
* we must deal with all other message/* types. RFC 2045 says
|
|
|
|
* message/* can only be 7bit or 8bit. RFC 2046 says unknown
|
|
|
|
* message/* types must be treated as application/octet-stream,
|
|
|
|
* which means we can't recurse into them. It also says that
|
|
|
|
* existing subtypes message/partial and message/external must only
|
|
|
|
* be 7bit, and that future subtypes "should be" 7bit.
|
|
|
|
*/
|
|
|
|
throw new MessagingException(
|
|
|
|
"Unable to convert 8bit body part to 7bit");
|
|
|
|
} else {
|
|
|
|
setEncoding(MimeUtil.ENC_QUOTED_PRINTABLE);
|
|
|
|
}
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|