james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r894881 - in /james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j: field/Fields.java message/Entity.java message/Message.java message/impl/BodyPart.java
Date Thu, 31 Dec 2009 16:28:23 GMT
Author: bago
Date: Thu Dec 31 16:28:22 2009
New Revision: 894881

URL: http://svn.apache.org/viewvc?rev=894881&view=rev
Log:
Refactored Entity and Message so to refer to "Fields" object only via protected methods. (MIME4J-156)

Modified:
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Fields.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
    james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Fields.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Fields.java?rev=894881&r1=894880&r2=894881&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Fields.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/field/Fields.java
Thu Dec 31 16:28:22 2009
@@ -295,7 +295,7 @@
      *            <code>null</code> if no host name should be included.
      * @return the newly created <i>Message-ID</i> field.
      */
-    public static Field messageId(String hostname) {
+    public static UnstructuredField messageId(String hostname) {
         String fieldValue = MimeUtil.createUniqueMessageId(hostname);
         return parse(UnstructuredField.PARSER, FieldName.MESSAGE_ID, fieldValue);
     }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java?rev=894881&r1=894880&r2=894881&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Entity.java
Thu Dec 31 16:28:22 2009
@@ -30,7 +30,6 @@
 import org.apache.james.mime4j.field.Field;
 import org.apache.james.mime4j.field.FieldName;
 import org.apache.james.mime4j.field.Fields;
-import org.apache.james.mime4j.util.MimeUtil;
 
 /**
  * MIME entity. An entity has a header and a body (see RFC 2045).
@@ -150,7 +149,7 @@
     public void setMultipart(Multipart multipart) {
         String mimeType = "multipart/" + multipart.getSubType();
         Map<String, String> parameters = Collections.singletonMap("boundary",
-                MimeUtil.createUniqueBoundary());
+                newUniqueBoundary());
 
         setBody(multipart, mimeType, parameters);
     }
@@ -170,7 +169,7 @@
         String mimeType = "multipart/" + multipart.getSubType();
         if (!parameters.containsKey("boundary")) {
             parameters = new HashMap<String, String>(parameters);
-            parameters.put("boundary", MimeUtil.createUniqueBoundary());
+            parameters.put("boundary", newUniqueBoundary());
         }
 
         setBody(multipart, mimeType, parameters);
@@ -247,7 +246,7 @@
         setBody(body);
 
         Header header = obtainHeader();
-        header.setField(Fields.contentType(mimeType, parameters));
+        header.setField(newContentType(mimeType, parameters));
     }
 
     /**
@@ -299,7 +298,7 @@
      */
     public void setContentTransferEncoding(String contentTransferEncoding) {
         Header header = obtainHeader();
-        header.setField(Fields.contentTransferEncoding(contentTransferEncoding));
+        header.setField(newContentTransferEncoding(contentTransferEncoding));
     }
 
     /**
@@ -316,7 +315,7 @@
 
         return field.getDispositionType();
     }
-    
+
     /**
      * Sets the content disposition of this <code>Entity</code> to the
      * specified disposition type. No filename, size or date parameters
@@ -328,8 +327,8 @@
      */
     public void setContentDisposition(String dispositionType) {
         Header header = obtainHeader();
-        header.setField(Fields.contentDisposition(dispositionType, null, -1,
-                null, null, null));
+        header.setField(newContentDisposition(dispositionType, null, -1, null,
+                null, null));
     }
 
     /**
@@ -346,8 +345,8 @@
      */
     public void setContentDisposition(String dispositionType, String filename) {
         Header header = obtainHeader();
-        header.setField(Fields.contentDisposition(dispositionType, filename,
-                -1, null, null, null));
+        header.setField(newContentDisposition(dispositionType, filename, -1,
+                null, null, null));
     }
 
     /**
@@ -368,8 +367,8 @@
     public void setContentDisposition(String dispositionType, String filename,
             long size) {
         Header header = obtainHeader();
-        header.setField(Fields.contentDisposition(dispositionType, filename,
-                size, null, null, null));
+        header.setField(newContentDisposition(dispositionType, filename, size,
+                null, null, null));
     }
 
     /**
@@ -398,8 +397,8 @@
     public void setContentDisposition(String dispositionType, String filename,
             long size, Date creationDate, Date modificationDate, Date readDate) {
         Header header = obtainHeader();
-        header.setField(Fields.contentDisposition(dispositionType, filename,
-                size, creationDate, modificationDate, readDate));
+        header.setField(newContentDisposition(dispositionType, filename, size,
+                creationDate, modificationDate, readDate));
     }
 
     /**
@@ -433,7 +432,7 @@
                 .getField(FieldName.CONTENT_DISPOSITION);
         if (field == null) {
             if (filename != null) {
-                header.setField(Fields.contentDisposition(
+                header.setField(newContentDisposition(
                         ContentDispositionField.DISPOSITION_TYPE_ATTACHMENT,
                         filename, -1, null, null, null));
             }
@@ -447,8 +446,7 @@
                 parameters
                         .put(ContentDispositionField.PARAM_FILENAME, filename);
             }
-            header.setField(Fields.contentDisposition(dispositionType,
-                    parameters));
+            header.setField(newContentDisposition(dispositionType, parameters));
         }
     }
 
@@ -472,10 +470,12 @@
      * @return <code>true</code> on match, <code>false</code> otherwise.
      */
     public boolean isMultipart() {
-        ContentTypeField f = 
-            (ContentTypeField) getHeader().getField(FieldName.CONTENT_TYPE);
-        return f != null && f.getBoundary() != null 
-            && getMimeType().startsWith(ContentTypeField.TYPE_MULTIPART_PREFIX);
+        ContentTypeField f = (ContentTypeField) getHeader().getField(
+                FieldName.CONTENT_TYPE);
+        return f != null
+                && f.getBoundary() != null
+                && getMimeType().startsWith(
+                        ContentTypeField.TYPE_MULTIPART_PREFIX);
     }
 
     /**
@@ -526,4 +526,28 @@
         return field;
     }
 
+    protected abstract String newUniqueBoundary();
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, String filename, long size,
+            Date creationDate, Date modificationDate, Date readDate) {
+        return Fields.contentDisposition(dispositionType, filename, size,
+                creationDate, modificationDate, readDate);
+    }
+
+    protected ContentDispositionField newContentDisposition(
+            String dispositionType, Map<String, String> parameters) {
+        return Fields.contentDisposition(dispositionType, parameters);
+    }
+
+    protected ContentTypeField newContentType(String mimeType,
+            Map<String, String> parameters) {
+        return Fields.contentType(mimeType, parameters);
+    }
+
+    protected ContentTransferEncodingField newContentTransferEncoding(
+            String contentTransferEncoding) {
+        return Fields.contentTransferEncoding(contentTransferEncoding);
+    }
+
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java?rev=894881&r1=894880&r2=894881&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/Message.java
Thu Dec 31 16:28:22 2009
@@ -48,6 +48,7 @@
 import org.apache.james.mime4j.parser.MimeStreamParser;
 import org.apache.james.mime4j.storage.DefaultStorageProvider;
 import org.apache.james.mime4j.storage.StorageProvider;
+import org.apache.james.mime4j.util.MimeUtil;
 
 /**
  * Represents a MIME message. The following code parses a stream into a
@@ -194,7 +195,7 @@
     public void createMessageId(String hostname) {
         Header header = obtainHeader();
 
-        header.setField(Fields.messageId(hostname));
+        header.setField(newMessageId(hostname));
     }
 
     /**
@@ -227,7 +228,7 @@
         if (subject == null) {
             header.removeFields(FieldName.SUBJECT);
         } else {
-            header.setField(Fields.subject(subject));
+            header.setField(newSubject(subject));
         }
     }
 
@@ -275,7 +276,7 @@
         if (date == null) {
             header.removeFields(FieldName.DATE);
         } else {
-            header.setField(Fields.date(FieldName.DATE, date, zone));
+            header.setField(newDate(date, zone));
         }
     }
 
@@ -551,7 +552,7 @@
         if (mailbox == null) {
             header.removeFields(fieldName);
         } else {
-            header.setField(Fields.mailbox(fieldName, mailbox));
+            header.setField(newMailbox(fieldName, mailbox));
         }
     }
 
@@ -579,7 +580,7 @@
         if (mailboxes == null || mailboxes.isEmpty()) {
             header.removeFields(fieldName);
         } else {
-            header.setField(Fields.mailboxList(fieldName, mailboxes));
+            header.setField(newMailboxList(fieldName, mailboxes));
         }
     }
 
@@ -607,8 +608,39 @@
         if (addresses == null || addresses.isEmpty()) {
             header.removeFields(fieldName);
         } else {
-            header.setField(Fields.addressList(fieldName, addresses));
+            header.setField(newAddressList(fieldName, addresses));
         }
     }
 
+	@Override
+	protected String newUniqueBoundary() {
+		return MimeUtil.createUniqueBoundary();
+	}
+
+	protected UnstructuredField newMessageId(String hostname) {
+		return Fields.messageId(hostname);
+	}
+
+	protected DateTimeField newDate(Date date, TimeZone zone) {
+		return Fields.date(FieldName.DATE, date, zone);
+	}
+
+	protected MailboxField newMailbox(String fieldName, Mailbox mailbox) {
+		return Fields.mailbox(fieldName, mailbox);
+	}
+
+	protected MailboxListField newMailboxList(String fieldName,
+			Collection<Mailbox> mailboxes) {
+		return Fields.mailboxList(fieldName, mailboxes);
+	}
+
+	private AddressListField newAddressList(String fieldName,
+			Collection<Address> addresses) {
+		return Fields.addressList(fieldName, addresses);
+	}
+
+	private UnstructuredField newSubject(String subject) {
+		return Fields.subject(subject);
+	}
+
 }

Modified: james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
URL: http://svn.apache.org/viewvc/james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java?rev=894881&r1=894880&r2=894881&view=diff
==============================================================================
--- james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
(original)
+++ james/mime4j/branches/cycleclean/core/src/main/java/org/apache/james/mime4j/message/impl/BodyPart.java
Thu Dec 31 16:28:22 2009
@@ -25,6 +25,7 @@
 import org.apache.james.mime4j.message.Message;
 import org.apache.james.mime4j.message.Multipart;
 import org.apache.james.mime4j.message.SingleBody;
+import org.apache.james.mime4j.util.MimeUtil;
 
 /**
  * Represents a MIME body part  (see RFC 2045).
@@ -65,4 +66,9 @@
         }
     }
 
+	@Override
+	protected String newUniqueBoundary() {
+		return MimeUtil.createUniqueBoundary();
+	}
+
 }



Mime
View raw message