ppkarwasz commented on issue #3704:
URL: 
https://github.com/apache/logging-log4j2/issues/3704#issuecomment-3080017458

   Hi @sidhantmourya,
   
   Thanks for digging into this!
   
   I must admit that when I introduced the Jakarta version of the SMTP 
appender, I only added a minimal abstraction for `MailManager`. In hindsight, I 
could have refactored more shared logic into the abstract base class. One 
reason I held back was that `SmtpManager` exposes Java EE Mail types in its 
public and protected methods, which we can’t remove without breaking backward 
compatibility.
   
   That said, if you'd like to take on abstracting `MimeMessage`, feel free — 
it would be a useful improvement. Alternatively, you're also welcome to 
duplicate the logic across both `MailManager` implementations. The Java EE 
version will be removed in Log4j 3.x anyway, so code duplication is a 
short-term compromise.
   
   A few quick notes on the code you shared:
   
   ```java
   setHeader.invoke(message, header.getName(), 
substitutor.replace(header.getValue()));
   ```
   
   When calling `MimeMessage.setHeader()`, make sure the value is correctly 
encoded and safe. Specifically:
   
   1. The value **must be ASCII-only**, per [RFC 5322, section 
2.2](https://datatracker.ietf.org/doc/html/rfc5322#section-2.2).
   2. It **must not contain newlines**, to avoid **header injection** 
vulnerabilities.
   3. It **must respect the 998-character line length limit**, per [RFC 5322, 
section 2.1.1](https://datatracker.ietf.org/doc/html/rfc5322#section-2.1.1). 
For example, I’ve seen overly long headers cause message rejection on a Debian 
server running Exim with default settings.
   
   To handle these constraints, you can use the `encode` and `fold` methods 
from 
[`MimeUtility`](https://jakarta.ee/specifications/platform/9/apidocs/jakarta/mail/internet/mimeutility).
   
   Finally, although `HttpAppender` only supports [property 
substitution](https://logging.apache.org/log4j/2.x/manual/configuration.html#property-substitution),
 I’d personally prefer we allow full `PatternLayout` expressions here — just 
like the "Subject" field is implemented in `SmtpManager`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to