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

ASF GitHub Bot commented on JAMES-2301:
---------------------------------------

Github user chibenwa commented on a diff in the pull request:

    https://github.com/apache/james-project/pull/123#discussion_r200584179
  
    --- Diff: 
server/queue/queue-jms/src/main/java/org/apache/james/queue/jms/JMSMailQueue.java
 ---
    @@ -297,27 +303,20 @@ protected void produceMail(Map<String, Object> props, 
int msgPrio, Mail mail) th
             props.put(JAMES_MAIL_MESSAGE_SIZE, mail.getMessageSize());
             props.put(JAMES_MAIL_NAME, mail.getName());
     
    -        StringBuilder recipientsBuilder = new StringBuilder();
    -
    -        Iterator<MailAddress> recipients = mail.getRecipients().iterator();
    -        while (recipients.hasNext()) {
    -            String recipient = recipients.next().toString();
    -            recipientsBuilder.append(recipient.trim());
    -            if (recipients.hasNext()) {
    -                recipientsBuilder.append(JAMES_MAIL_SEPARATOR);
    -            }
    +        // won't serialize the empty headers so it is mandatory
    +        // to handle nulls when reconstructing mail from message
    +        if 
(!mail.getPerRecipientSpecificHeaders().getHeadersByRecipient().isEmpty()) {
    +            byte[] serialize = 
SerializationUtils.serialize(mail.getPerRecipientSpecificHeaders());
    +            props.put(JAMES_MAIL_PER_RECIPIENT_HEADERS, 
Hex.encodeHexString(serialize));
             }
    -        props.put(JAMES_MAIL_RECIPIENTS, recipientsBuilder.toString());
    +
    +        String recipientsBuilder = 
Joiner.on(JAMES_MAIL_SEPARATOR).skipNulls().join(mail.getRecipients());
    +
    +        props.put(JAMES_MAIL_RECIPIENTS, recipientsBuilder);
             props.put(JAMES_MAIL_REMOTEADDR, mail.getRemoteAddr());
             props.put(JAMES_MAIL_REMOTEHOST, mail.getRemoteHost());
     
    -        String sender;
    -        MailAddress s = mail.getSender();
    -        if (s == null) {
    -            sender = "";
    -        } else {
    -            sender = mail.getSender().toString();
    -        }
    +        String sender = 
Optional.ofNullable(mail.getSender()).map(MailAddress::toString).orElse("");
    --- End diff --
    
    Use `asString` instead of `toString`.
    
    toString generally serves for debugging, and it's value can change...


> JMS mail queue do not preserve per-recipient headers
> ----------------------------------------------------
>
>                 Key: JAMES-2301
>                 URL: https://issues.apache.org/jira/browse/JAMES-2301
>             Project: James Server
>          Issue Type: Bug
>          Components: Queue
>    Affects Versions: master
>            Reporter: Tellier Benoit
>            Priority: Major
>             Fix For: master
>
>
> The JMS mail queue reset this email field.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to