2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2010-02-04 18:37:50 -05:00
|
|
|
import com.fsck.k9.mail.internet.MimeHeader;
|
|
|
|
import com.fsck.k9.mail.internet.TextBody;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public abstract class Multipart implements Body
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
protected Part mParent;
|
|
|
|
|
|
|
|
protected ArrayList<BodyPart> mParts = new ArrayList<BodyPart>();
|
|
|
|
|
|
|
|
protected String mContentType;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void addBodyPart(BodyPart part) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mParts.add(part);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void addBodyPart(BodyPart part, int index) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mParts.add(index, part);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public BodyPart getBodyPart(int index) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mParts.get(index);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getContentType() throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mContentType;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public int getCount() throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mParts.size();
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean removeBodyPart(BodyPart part) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mParts.remove(part);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void removeBodyPart(int index) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mParts.remove(index);
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Part getParent() throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setParent(Part parent) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mParent = parent;
|
|
|
|
}
|
2010-02-04 18:37:50 -05:00
|
|
|
|
|
|
|
public void setEncoding(String encoding)
|
|
|
|
{
|
|
|
|
for (BodyPart part : mParts)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Body body = part.getBody();
|
|
|
|
if (body instanceof TextBody)
|
|
|
|
{
|
|
|
|
part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
|
|
|
|
((TextBody)body).setEncoding(encoding);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (MessagingException e)
|
|
|
|
{
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|