james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "leviluo (JIRA)" <server-...@james.apache.org>
Subject [jira] [Commented] (JAMES-1910) can't add footer when use email client (ex:foxmail)
Date Mon, 16 Jan 2017 11:02:26 GMT

    [ https://issues.apache.org/jira/browse/JAMES-1910?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15823784#comment-15823784
] 

leviluo commented on JAMES-1910:
--------------------------------

I resolve this issue by reference https://issues.apache.org/jira/browse/JAMES-443
I didn't realize this issue didn't submit to repository.
we need change some code as below 
{quote}
 private boolean attachFooter(MimePart part) throws MessagingException, IOException {
        String contentType = part.getContentType();
        if (part.getContent() instanceof String) {
            Optional<String> content = attachFooterToTextPart(part);
            if (content.isPresent()) {
                part.setContent(content.get(), contentType);
                part.setHeader(RFC2822Headers.CONTENT_TYPE, contentType);
                return true;
            }
        }
        if (part.isMimeType("multipart/mixed")
                || part.isMimeType("multipart/related")) {
            MimeMultipart multipart = (MimeMultipart) part.getContent();
            boolean attachFooterToAllSubparts =  attachFooterToFirstPart(multipart);
            part.setContent(multipart);
            return attachFooterToAllSubparts;

        } else if (part.isMimeType("multipart/alternative")) {
            MimeMultipart multipart = (MimeMultipart) part.getContent();
            boolean attachFooterToAllSubparts = attachFooterToAllSubparts(multipart);
            part.setContent(multipart);
            return attachFooterToAllSubparts;
        }
        //Give up... we won't attach the footer to this MimePart
        return false;
    }
{quote}
The important is set the content back when the content change.
If need some one could change and submit it as rule.
 

> can't add footer when use email client (ex:foxmail)
> ---------------------------------------------------
>
>                 Key: JAMES-1910
>                 URL: https://issues.apache.org/jira/browse/JAMES-1910
>             Project: James Server
>          Issue Type: Bug
>          Components: Mailet Contributions
>    Affects Versions: 3.0.0-beta5
>            Reporter: leviluo
>            Priority: Critical
>              Labels: patch
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> config as below
> {quote}
> <mailet match="All" class="org.apache.james.transport.mailets.AddFooter">
>  				<text>================================add footer=======================</text>

>  		</mailet>
> {quote}
> I can get the footer when I use telnet wiht simple message. and I change the email content
to text at server  just like below code.I think this change the message type.
> {quote}
>     public void service(Mail mail) throws MessagingException {
>         try {
>             MimeMessage message = mail.getMessage();
>             message.setText("11111111111111111111");
> //            message.getContent();
>             if (attachFooter(message)) {
>                 message.saveChanges();
>             } else {
>                 log("Unable to add footer to mail " + mail.getName());
>             }
>         } catch (UnsupportedEncodingException e) {
>             log("UnsupportedEncoding Unable to add footer to mail "
>                     + mail.getName());
>         } catch (IOException ioe) {
>             throw new MessagingException("Could not read message", ioe);
>         }
>     }
> {quote}
>  But i run the test case of AddFooterTest.java, It is work fine.
> I add a test case for the same content of the foxmail client.and the test case is OK.
> Test case in AddFooterTest as below 
> {quote}
>  @Test
>     public void shouldAddFooterWhenMultipartRelatedHtmlMessage4() throws MessagingException,
IOException {
>         mailetConfig.setProperty("text", "==========================test case============================");
>         mailet.init(mailetConfig);
>         
>         String htmlMultipartRelatedMessagePart1 = Joiner.on("\r\n").join(
>         		"MIME-Version: 1.0",
> "Received: from 127.0.0.1 (EHLO levi-work) ([127.0.0.1])",
> "          by levi-work (JAMES SMTP Server ) with ESMTP ID 2126899460",
> "          for <luolei@linyanyan.cn>;",
> "          Mon, 16 Jan 2017 14:00:53 +0800 (CST)",
> "Date: Mon, 16 Jan 2017 14:00:53 +0800",
> "From: \"test@linyanyan.cn\" <test@linyanyan.cn>",
> "To: \"luolei@linyanyan.cn\" <luolei@linyanyan.cn>",
> "Subject: 01-16-15",
> "References: <2017011417484072410935@linyanyan.cn>, ",
> "	<2017011611300751098536@linyanyan.cn>, ",
> "	<2017011611571368034137@linyanyan.cn>, ",
> "	<2017011612310328703438@linyanyan.cn>, ",
> "	<2017011612342956932739@linyanyan.cn>, ",
> "	<2017011612433319053540@linyanyan.cn>, ",
> "	<2017011612452625583641@linyanyan.cn>, ",
> "	<2017011613055188853642@linyanyan.cn>, ",
> "	<2017011613071917921943@linyanyan.cn>, ",
> "	<2017011613080283758744@linyanyan.cn>, ",
> "	<2017011613094076349445@linyanyan.cn>, ",
> "	<2017011613184900040846@linyanyan.cn>, ",
> "	<2017011613210755849247@linyanyan.cn>, ",
> "	<2017011613371787777048@linyanyan.cn>",
> "X-Priority: 3",
> "X-Has-Attach: no",
> "X-Mailer: Foxmail 7, 2, 7, 26[cn]",
> "Content-Type: multipart/alternative;",
> "	boundary=\"----=_001_NextPart801803664644_=----\"",
> "			",
> "This is a multi-part message in MIME format.",
> "",
> "------=_001_NextPart801803664644_=----",
> "Content-Type: text/plain;",
> "	charset=\"ISO-8859-1\"",
> "Content-Transfer-Encoding: base64",
> "",
> "WFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhY",
> "WFhYWFhYWFhYDQo=",
> "",
> "------=_001_NextPart801803664644_=----",
> "Content-Type: text/html;",
> "	charset=\"ISO-8859-1\"",
> "Content-Transfer-Encoding: quoted-printable",
> "",
> "<html><head><meta http-equiv=3D\"content-type\" content=3D\"text/html;
charse=",
> "t=3DISO-8859-1\"><style>body { line-height: 1.5; }blockquote { margin-top:
=",
> "0px; margin-bottom: 0px; margin-left: 0.5em; }div.foxdiv201701161400456737=",
> "13 { }body { font-size: 10.5pt; font-family: ??; color: rgb(0, 0, 0); line=",
> "-height: 1.5; }</style></head><body>=0A<div><span></span></div><blockquote=",
> " style=3D\"margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;\"><div><=",
> "div class=3D\"FoxDiv20170116140045673713\"><blockquote style=3D\"margin-top: =",
> "0px; margin-bottom: 0px; margin-left: 0.5em;\"><div><div class=3D\"FoxDiv201=",
> "70116133708224697\"><blockquote style=3D\"margin-top: 0px; margin-bottom: 0p=",
> "x; margin-left: 0.5em;\"><div><div class=3D\"FoxDiv20170116132059834934\"><bl=",
> "ockquote style=3D\"margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;=",
> "\"><div><div class=3D\"FoxDiv20170116131842479478\"><blockquote style=3D\"marg=",
> "in-top: 0px; margin-bottom: 0px; margin-left: 0.5em;\"><div><div class=3D\"F=",
> "oxDiv20170116130934388968\"><blockquote style=3D\"margin-top: 0px; margin-bo=",
> "ttom: 0px; margin-left: 0.5em;\"><div><div class=3D\"FoxDiv20170116130734603=",
> "789\"><blockquote style=3D\"margin-top: 0px; margin-bottom: 0px; margin-left=",
> ": 0.5em;\"><div><div class=3D\"FoxDiv20170116130712731671\"><blockquote
style=",
> "=3D\"margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;\"><div><div
cl=",
> "ass=3D\"FoxDiv20170116130541763948\"><blockquote style=3D\"margin-top: 0px; m=",
> "argin-bottom: 0px; margin-left: 0.5em;\"><div><div class=3D\"FoxDiv201701161=",
> "24514335323\"><blockquote style=3D\"margin-top: 0px; margin-bottom: 0px; mar=",
> "gin-left: 0.5em;\"><div><div class=3D\"FoxDiv20170116124321987400\"><blockquo=",
> "te style=3D\"margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;\"><div=",
> "><div class=3D\"FoxDiv20170116123422143022\"><blockquote style=3D\"margin-top=",
> ": 0px; margin-bottom: 0px; margin-left: 0.5em;\"><div><div class=3D\"FoxDiv2=",
> "0170116123055868282\"><blockquote style=3D\"margin-top: 0px; margin-bottom: =",
> "0px; margin-left: 0.5em;\"><div class=3D\"FoxDiv20170116115703081740\"><div><=",
> "span style=3D\"font-size: 10.5pt; line-height: 1.5; background-color: windo=",
> "w;\">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</sp=",
> "an></div><blockquote style=3D\"margin-top: 0px; margin-bottom: 0px; margin-=",
> "left: 0.5em;\"><div><div class=3D\"FoxDiv20170116112952258988\">=0A</div></di=",
> "v></blockquote>=0A</div></blockquote>=0A</div></div></blockquote>=0A</div>=",
> "</div></blockquote>=0A</div></div></blockquote>=0A</div></div></blockquote=",
> ">=0A</div></div></blockquote>=0A</div></div></blockquote>=0A</div></div></=",
> "blockquote>=0A</div></div></blockquote>=0A</div></div></blockquote>=0A</di=",
> "v></div></blockquote>=0A</div></div></blockquote>=0A</div></div></blockquo=",
> "te>=0A</body></html>",
> "------=_001_NextPart801803664644_=------",
> "");
>         Mail mail = FakeMail.fromMime(htmlMultipartRelatedMessagePart1 , javaCharset,
javaMailCharset);
>         mailet.service(mail);
> //        assertThat(MailUtil.toString(mail, javaCharset)).isEqualTo("YWFhYWFhYWFhYmJiYmJiYg0K");
>     }
> {quote}
> I try my best to solve, But i Don't know how to solve it. 
> If any advise will appreciation!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message