Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Merge branch 'fix/mailbox-ugly-newlines'
Browse files Browse the repository at this point in the history
* fix/mailbox-ugly-newlines:
  mailbox: Remove ugly newlines from an issue submitted via email

Reviewed-by: 채수원 <[email protected]>
  • Loading branch information
Yi EungJun committed Jul 7, 2015
2 parents 0fbd744 + 118cf90 commit a5c9992
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
26 changes: 20 additions & 6 deletions app/mailbox/CreationViaEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package mailbox;

import com.sun.mail.imap.IMAPMessage;
import com.googlecode.htmlcompressor.compressor.HtmlCompressor;
import mailbox.exceptions.IssueNotFound;
import mailbox.exceptions.MailHandlerException;
import mailbox.exceptions.PermissionDenied;
Expand Down Expand Up @@ -89,9 +90,7 @@ public static Comment saveComment(IMAPMessage message, Resource target)
comment.asResource());

if (new ContentType(parsedMessage.type).match(MimeType.HTML)) {
// replace cid with attachments
comment.contents = replaceCidWithAttachments(
comment.contents, relatedAttachments);
comment.contents = postprocessForHTML(comment.contents, relatedAttachments);
comment.update();
}

Expand All @@ -104,6 +103,23 @@ public static Comment saveComment(IMAPMessage message, Resource target)
return comment;
}

/**
* Does postprocessing for HTML document.
*
* 1. Replaces cid with attachments.
* 2. Removes newlines between HTML tags which will make the result rendered
* by markdown ugly.
*
* @param contents
* @param relatedAttachments
* @return
*/
private static String postprocessForHTML(
String contents, Map<String, Attachment> relatedAttachments) {
return new HtmlCompressor().compress(
replaceCidWithAttachments(contents, relatedAttachments));
}

private static Comment makeNewComment(Resource target, User sender, String body) throws IssueNotFound, PostingNotFound {
Comment comment;
Long id = Long.valueOf(target.getId());
Expand Down Expand Up @@ -174,9 +190,7 @@ public static Issue saveIssue(String subject,
issue.asResource());

if (new ContentType(parsedMessage.type).match(MimeType.HTML)) {
// replace cid with attachments
issue.body = replaceCidWithAttachments(
issue.body, relatedAttachments);
issue.body = postprocessForHTML(issue.body, relatedAttachments);
issue.update();
}

Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ libraryDependencies ++= Seq(
"com.googlecode.juniversalchardet" % "juniversalchardet" % "1.0.3",
"org.mockito" % "mockito-all" % "1.9.0" % "test",
"com.github.zafarkhaja" % "java-semver" % "0.7.2",
"com.google.guava" % "guava" % "18.0"
"com.google.guava" % "guava" % "18.0",
"com.googlecode.htmlcompressor" % "htmlcompressor" % "1.4"
)

val projectSettings = Seq(
Expand Down

0 comments on commit a5c9992

Please sign in to comment.