camunda-platform-7-mail icon indicating copy to clipboard operation
camunda-platform-7-mail copied to clipboard

Error on unit test PollMailConnectorTest.htmlMessage: Don't send Mime Multipart

Open joaopalma5 opened this issue 4 years ago • 7 comments

In htmlMessage: https://github.com/camunda-community-hub/camunda-bpm-mail/blob/master/extension/core/src/test/java/org/camunda/bpm/extension/mail/poll/PollMailConnectorTest.java#L168

Get this error: org.junit.ComparisonFailure: Expected :"html" Actual :"" at org.camunda.bpm.extension.mail.poll.PollMailConnectorTest.htmlMessage(PollMailConnectorTest.java:168)

Similar cases:

  • https://stackoverflow.com/questions/25626301/javamail-does-not-send-message-content

joaopalma5 avatar Aug 23 '21 18:08 joaopalma5

Hi @joaopalma5 -- I merged a change to the code in question on L168 that may resolve this error! If you would be so kind as to re-run your tests and see if it's resolved, that would be great! :) Thank you so much.

celanthe avatar Aug 23 '21 18:08 celanthe

@celanthe , the problem is when is sending or receiving... Not is in the assert.

I set this option: session.setDebug(true); and I get this output:

DEBUG: setDebug: JavaMail version 1.6.2
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "127.0.0.1", port 3025, isSSL false
220 /127.0.0.1 GreenMail SMTP Service Ready at port 3025
DEBUG SMTP: connected to host "127.0.0.1", port: 3025
EHLO 127.0.0.1
250 /127.0.0.1
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
250 OK
RCPT TO:<[email protected]>
250 OK
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   [email protected]
DATA
354 Start mail input; end with <CRLF>.<CRLF>
Date: Mon, 23 Aug 2021 19:21:50 +0100 (BST)
From: [email protected]
To: [email protected]
Message-ID: <1354011814.1.1629742910180@[10.100.1.23]>
Subject: subject
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_0_1843368112.1629742910118"

------=_Part_0_1843368112.1629742910118
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

text
------=_Part_0_1843368112.1629742910118
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit

<b>html</b>
------=_Part_0_1843368112.1629742910118--
.
250 OK
DEBUG SMTP: message successfully delivered to mail server
QUIT
221 /127.0.0.1 Service closing transmission channel```

Based in output, I think the error it is in received part... What you think?

joaopalma5 avatar Aug 23 '21 18:08 joaopalma5

@celanthe You run the test in your computer? What is the output?

joaopalma5 avatar Aug 23 '21 18:08 joaopalma5

Hi @joaopalma5 -- I've not run it on my machine. My above fixwas made in an effort to resolve the error on L168 in https://github.com/camunda-community-hub/camunda-bpm-mail/blob/master/extension/core/src/test/java/org/camunda/bpm/extension/mail/poll/PollMailConnectorTest.java#L168 where (to me, at least...) it appears that the <b> and </b> tags may be causing an issue.

I will look into this further and get back to you ASAP! :)

celanthe avatar Aug 23 '21 18:08 celanthe

I made more tests, I will share bellow:

In https://github.com/camunda-community-hub/camunda-bpm-mail/blob/master/extension/core/src/main/java/org/camunda/bpm/extension/mail/poll/PollMailResponse.java#L72 , put this method:

 public void exp(){
    System.out.println("xpto");
    try {
      Multipart mp = (Multipart) messages.get(0).getContent();
      System.out.println("------------------ 1st Part ---------");
      MimeBodyPart mbp = (MimeBodyPart) mp.getBodyPart(0);
      System.out.println(mp.getBodyPart(0).getContentType());
      System.out.println(mbp.getContent());
      System.out.println("------------------ 2nd Part ---------");
      System.out.println(mp.getBodyPart(1).getContentType());
      System.out.println(mp.getBodyPart(1).getContent());
    } catch (IOException e) {
      e.printStackTrace();
    } catch (MessagingException e) {
      e.printStackTrace();
    }
  }

And Call in https://github.com/camunda-community-hub/camunda-bpm-mail/blob/master/extension/core/src/test/java/org/camunda/bpm/extension/mail/poll/PollMailConnectorTest.java#L163, like:

response.exp();

Will get:

------------------ 1st Part ---------
TEXT/PLAIN; charset=us-ascii
16:27:03.784 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestHandler - C: tag=addedByEsetSecurity_A8, command=FETCH
16:27:03.785 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestLineReader - IMAP Line received : <addedByEsetSecurity_A8 FETCH 1 (uid BODY[1.MIME] ENVELOPE)\r\n>
16:27:03.786 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.commands.FetchCommand - Fetching body part for section specifier 1.MIME and mime message (contentType=multipart/mixed; 
	boundary="----=_Part_0_1376400422.1629818823235"
16:27:03.790 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestHandler - C: tag=A8, command=FETCH
16:27:03.790 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestLineReader - IMAP Line received : <A8 FETCH 1 (uid BODY[1])\r\n>
16:27:03.790 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.commands.FetchCommand - Fetching body part for section specifier 1 and mime message (contentType=multipart/mixed; 
	boundary="----=_Part_0_1376400422.1629818823235"

------------------ 2nd Part ---------
TEXT/HTML; charset=utf-8
16:27:03.804 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestHandler - C: tag=addedByEsetSecurity_A9, command=FETCH
16:27:03.805 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestLineReader - IMAP Line received : <addedByEsetSecurity_A9 FETCH 1 (uid BODY[2.MIME] ENVELOPE)\r\n>
16:27:03.805 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.commands.FetchCommand - Fetching body part for section specifier 2.MIME and mime message (contentType=multipart/mixed; 
	boundary="----=_Part_0_1376400422.1629818823235"
16:27:03.806 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestHandler - C: tag=A9, command=FETCH
16:27:03.807 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.ImapRequestLineReader - IMAP Line received : <A9 FETCH 1 (uid BODY[2])\r\n>
16:27:03.807 [imap:127.0.0.1:3143<-/127.0.0.1:52747] DEBUG c.i.g.imap.commands.FetchCommand - Fetching body part for section specifier 2 and mime message (contentType=multipart/mixed; 
	boundary="----=_Part_0_1376400422.1629818823235"

The type is correct but I can't obtain the content.

joaopalma5 avatar Aug 24 '21 15:08 joaopalma5

Hello @celanthe, just want to let you know that the assert in PollMailConnectorTest is failing with:

org.junit.ComparisonFailure: 
Expected :"html"
Actual   :"<b>html</b>"

Reverting the change in faf629c commit would fix it.

standev avatar Jan 18 '22 16:01 standev

Hi @standev! Thank you kindly for the clear advice. I have reverted the commit in question. :) @joaopalma5, I hope this helps!

celanthe avatar Jan 19 '22 14:01 celanthe

Hello @joaopalma5 , could you please catch up with the main branch and try again. If the bug persists, feel free to open a new bug report.

jonathanlukas avatar Sep 16 '22 13:09 jonathanlukas