1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-12 22:28:10 -05:00

Added a getBodyparts method to Multipart so that foreach loops can be used. Removed unnecessary mutators from Multipart.

This commit is contained in:
Tobias Baum 2014-09-14 11:13:34 +02:00
parent 5513d5a99b
commit 545dd0db06
2 changed files with 14 additions and 33 deletions

View File

@ -2,6 +2,8 @@
package com.fsck.k9.mail; package com.fsck.k9.mail;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.james.mime4j.util.MimeUtil; import org.apache.james.mime4j.util.MimeUtil;
@ -20,15 +22,14 @@ public abstract class Multipart implements CompositeBody {
part.setParent(this); part.setParent(this);
} }
public void addBodyPart(BodyPart part, int index) {
mParts.add(index, part);
part.setParent(this);
}
public BodyPart getBodyPart(int index) { public BodyPart getBodyPart(int index) {
return mParts.get(index); return mParts.get(index);
} }
public List<BodyPart> getBodyParts() {
return Collections.unmodifiableList(mParts);
}
public String getContentType() { public String getContentType() {
return mContentType; return mContentType;
} }
@ -37,16 +38,6 @@ public abstract class Multipart implements CompositeBody {
return mParts.size(); return mParts.size();
} }
public boolean removeBodyPart(BodyPart part) {
part.setParent(null);
return mParts.remove(part);
}
public void removeBodyPart(int index) {
mParts.get(index).setParent(null);
mParts.remove(index);
}
public Part getParent() { public Part getParent() {
return mParent; return mParent;
} }
@ -55,6 +46,7 @@ public abstract class Multipart implements CompositeBody {
this.mParent = parent; this.mParent = parent;
} }
@Override
public void setEncoding(String encoding) throws MessagingException { public void setEncoding(String encoding) throws MessagingException {
if (!MimeUtil.ENC_7BIT.equalsIgnoreCase(encoding) if (!MimeUtil.ENC_7BIT.equalsIgnoreCase(encoding)
&& !MimeUtil.ENC_8BIT.equalsIgnoreCase(encoding)) { && !MimeUtil.ENC_8BIT.equalsIgnoreCase(encoding)) {

View File

@ -993,8 +993,7 @@ public class MimeUtility {
throws MessagingException { throws MessagingException {
if (part.getBody() instanceof Multipart) { if (part.getBody() instanceof Multipart) {
Multipart multipart = (Multipart)part.getBody(); Multipart multipart = (Multipart)part.getBody();
for (int i = 0, count = multipart.getCount(); i < count; i++) { for (BodyPart bodyPart : multipart.getBodyParts()) {
BodyPart bodyPart = multipart.getBodyPart(i);
Part ret = findFirstPartByMimeType(bodyPart, mimeType); Part ret = findFirstPartByMimeType(bodyPart, mimeType);
if (ret != null) { if (ret != null) {
return ret; return ret;
@ -1009,8 +1008,7 @@ public class MimeUtility {
public static Part findPartByContentId(Part part, String contentId) throws Exception { public static Part findPartByContentId(Part part, String contentId) throws Exception {
if (part.getBody() instanceof Multipart) { if (part.getBody() instanceof Multipart) {
Multipart multipart = (Multipart)part.getBody(); Multipart multipart = (Multipart)part.getBody();
for (int i = 0, count = multipart.getCount(); i < count; i++) { for (BodyPart bodyPart : multipart.getBodyParts()) {
BodyPart bodyPart = multipart.getBodyPart(i);
Part ret = findPartByContentId(bodyPart, contentId); Part ret = findPartByContentId(bodyPart, contentId);
if (ret != null) { if (ret != null) {
return ret; return ret;
@ -1490,9 +1488,7 @@ public class MimeUtility {
} }
} else { } else {
// For all other multipart parts we recurse to grab all viewable children. // For all other multipart parts we recurse to grab all viewable children.
int childCount = multipart.getCount(); for (Part bodyPart : multipart.getBodyParts()) {
for (int i = 0; i < childCount; i++) {
Part bodyPart = multipart.getBodyPart(i);
viewables.addAll(getViewables(bodyPart, attachments)); viewables.addAll(getViewables(bodyPart, attachments));
} }
} }
@ -1547,9 +1543,7 @@ public class MimeUtility {
throws MessagingException { throws MessagingException {
List<Viewable> viewables = new ArrayList<Viewable>(); List<Viewable> viewables = new ArrayList<Viewable>();
int childCount = multipart.getCount(); for (Part part : multipart.getBodyParts()) {
for (int i = 0; i < childCount; i++) {
Part part = multipart.getBodyPart(i);
Body body = part.getBody(); Body body = part.getBody();
if (body instanceof Multipart) { if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body; Multipart innerMultipart = (Multipart) body;
@ -1612,9 +1606,7 @@ public class MimeUtility {
List<Viewable> viewables = new ArrayList<Viewable>(); List<Viewable> viewables = new ArrayList<Viewable>();
boolean partFound = false; boolean partFound = false;
int childCount = multipart.getCount(); for (Part part : multipart.getBodyParts()) {
for (int i = 0; i < childCount; i++) {
Part part = multipart.getBodyPart(i);
Body body = part.getBody(); Body body = part.getBody();
if (body instanceof Multipart) { if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body; Multipart innerMultipart = (Multipart) body;
@ -1698,9 +1690,7 @@ public class MimeUtility {
*/ */
private static void findAttachments(Multipart multipart, Set<Part> knownTextParts, private static void findAttachments(Multipart multipart, Set<Part> knownTextParts,
List<Part> attachments) { List<Part> attachments) {
int childCount = multipart.getCount(); for (Part part : multipart.getBodyParts()) {
for (int i = 0; i < childCount; i++) {
Part part = multipart.getBodyPart(i);
Body body = part.getBody(); Body body = part.getBody();
if (body instanceof Multipart) { if (body instanceof Multipart) {
Multipart innerMultipart = (Multipart) body; Multipart innerMultipart = (Multipart) body;
@ -3422,8 +3412,7 @@ public class MimeUtility {
} else if (part.isMimeType("multipart/alternative") && } else if (part.isMimeType("multipart/alternative") &&
firstBody instanceof MimeMultipart) { firstBody instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) firstBody; MimeMultipart multipart = (MimeMultipart) firstBody;
for (int i = 0, count = multipart.getCount(); i < count; i++) { for (BodyPart bodyPart : multipart.getBodyParts()) {
BodyPart bodyPart = multipart.getBodyPart(i);
String bodyText = getTextFromPart(bodyPart); String bodyText = getTextFromPart(bodyPart);
if (bodyText != null) { if (bodyText != null) {
if (text.isEmpty() && bodyPart.isMimeType("text/plain")) { if (text.isEmpty() && bodyPart.isMimeType("text/plain")) {