Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail sending appears to not handle multiple "to" addresses properly #338

Open
jesse-gallagher opened this issue Aug 24, 2022 · 7 comments
Open
Labels
bug Something isn't working

Comments

@jesse-gallagher
Copy link
Collaborator

From the report:

====

When we use KEEP PIM endpoint /message to send mail, if there are 2 mail addresses in "To" or "CC" fields, the mail could not be delivered. In KEEP code, we constructed a MimeMessage first and then call JNX api to generate a Notes mail document according to the MimeMessage. Finally, JNX C code will do the work. I believe that JNX code does not handle the multiple values of mail addresses correctly.
// Create Mime message
final MimeMessage mime =
CreateMessage.createMimeMessage(payload.getString("from"), payload.getJsonArray("to"),
payload.getJsonArray("bccto"), payload.getJsonArray("copyto"),
payload.getString("subject"), body,
payload.getJsonObject("body").getString("content-type"));
final Document note = request.db.createDocument();
request.session.writeRawMIME(note, in);

public class JNAMimeWriter extends JNAMimeBase implements MimeWriter {

@OverRide
public void writeMime(Document doc, String itemName, InputStream in, Set dataType) throws IOException {
IOException[] ioEx = new IOException[1];

    writeMime(doc, itemName, (mimeStreamPtr) -> {

        byte[] buffer = new byte[60000];
        int len;

        DisposableMemory bufferMem = new DisposableMemory(buffer.length);
        try {
            while ((len=in.read(buffer))>0) {
                bufferMem.write(0, buffer,0, len);

                int resultAsInt = NotesCAPI.get().MIMEStreamWrite(bufferMem, len, mimeStreamPtr);

                if (resultAsInt == NotesConstants.MIME_STREAM_IO) {
                    throw new IOException("I/O error received during MIME stream operation");
                }
            }
        }
        catch (IOException e) {
            ioEx[0] = e;
            return;
        }
        finally {
            bufferMem.dispose();
        }
    }, dataType);

    if (ioEx[0] != null) {
        throw ioEx[0];
    }
}
@jesse-gallagher jesse-gallagher added the bug Something isn't working label Aug 24, 2022
@klehmann
Copy link
Collaborator

Do you have a sample MIME output that produces the issue?

@jesse-gallagher
Copy link
Collaborator Author

Not yet - so far, that report from chat is the entirety of my information.

@jesse-gallagher
Copy link
Collaborator Author

From a followup:

=======

In the MimeMessage, we created To field as below.

3693911e-b114-40c7-a966-d7dbf362512c

Then we use JNAMimeWriter.writeMime() to create a Notes document by the MimeMessage. The "sendTo" field of Notes document we created is not correct(see below). It should have 2 elements not one element with 2 email addresses in it.

66c1cc23-7a3b-429d-b88e-7727db696f00

@jesse-gallagher
Copy link
Collaborator Author

I added a test case for this: https://github.com/HCL-TECH-SOFTWARE/domino-jnx/blob/develop/test/it-domino-jnx/src/test/java/it/com/hcl/domino/test/mime/TestMimeReadWrite.java#L223 . However, it seems like it works properly there, where calling addTo in the Apache Commons Mail wrapper ends up writing the item as a multi-value text field with the right addresses. I'm checking with the reporter to see if this may be instead something in the intermediate layer.

@jesse-gallagher
Copy link
Collaborator Author

jesse-gallagher commented Aug 26, 2022

On further investigation, I believe this to be a problem on the app side. The value is being read via doc#getItemValue without calling Item#convertRFC822TextItem, and so the value won't be expanded out into a text list during that processing.

@klehmann
Copy link
Collaborator

As an alternative I think there is an open flag to convert RFC822 items, but then the doc should not be saved.

@jesse-gallagher
Copy link
Collaborator Author

That makes sense too. The new method I added should be convenient for already-open notes, and either way I'll leave this open just for a bit for confirmation from their side that this is the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants