[
https://issues.apache.org/jira/browse/JAMES-2171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16730142#comment-16730142
]
ASF GitHub Bot commented on JAMES-2171:
---------------------------------------
Github user chibenwa commented on a diff in the pull request:
https://github.com/apache/james-project/pull/145#discussion_r244284302
--- Diff:
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
---
@@ -100,25 +131,55 @@ public void service(Mail mail) {
}
}
+ private void logAttribute(Mail mail) {
+ if (!specificAttributeNames.isEmpty()) {
+ logBuffer.get().append('\n');
+ for (String name : specificAttributeNames) {
+ AttributeName attributeName = AttributeName.of(name);
+ Optional<Attribute> attribute =
mail.getAttribute(attributeName);
+ if (attribute.isPresent()) {
+ logBuffer.get().append(name + ": " +
attribute.get().getValue().value() + '\n');
+ } else {
+ logBuffer.get().append(name + ": \n");
+ }
+ }
+ }
+ }
+
private void logComment() {
if (comment != null) {
- logger.info(comment);
+ logBuffer.get().append(comment);
}
}
- private void logHeaders(MimeMessage message) throws MessagingException
{
+ private void logHeaders(Mail mail) throws MessagingException {
if (headers && logger.isInfoEnabled()) {
- logger.info("\n");
+ logBuffer.get().append('\n');
+ MimeMessage message = mail.getMessage();
for (String header :
Collections.list(message.getAllHeaderLines())) {
- logger.info(header + "\n");
+ logBuffer.get().append(header + '\n');
+ }
+
+ if (!specificHeaderNames.isEmpty()) {
+ for (MailAddress recipient : mail.getRecipients()) {
+ List<PerRecipientHeaders.Header> headers =
mail.getPerRecipientSpecificHeaders()
+ .getHeadersForRecipient(recipient).stream()
+ .filter(header ->
specificHeaderNames.contains(header.getName()))
+ .collect(Collectors.toList());
+ logBuffer.get().append("Recipient " +
recipient.asPrettyString() + "'s headers are: \n");
+ for (PerRecipientHeaders.Header header : headers) {
+ logBuffer.get().append(header.getName() + ": " +
header.getValue() + '\n');
--- End diff --
This, as all the for loops you introduced in this class could easily be
replaced by a foreach.
> LogMessage mailet improvments
> -----------------------------
>
> Key: JAMES-2171
> URL: https://issues.apache.org/jira/browse/JAMES-2171
> Project: James Server
> Issue Type: Improvement
> Components: Mailet Contributions
> Affects Versions: master
> Reporter: Tellier Benoit
> Priority: Major
> Labels: easyfix, newbie
>
> Today, one can use the LogMessage to generate log messages upon mail reception
> But the LogMessage have the following limits:
> - It do not let you configure the warn level
> - It does generate several logs. One would be simpler to review.
> - It does add some unneeded informations, like mail name already carried by
> the MDC
> - It does not allow logging of specific headers or specific attributeNames.
> This leads to missing information as well as "to much information".
> - The code quality of the mailet is poor.
> You will:
> - Ensure a single log message will be generated. For this you will call the
> logger one time and concatenate log messages parts.
> - Remove the log line with mail name.
> - Add a **level** configuration option. It can takes value **warn**,
> **info**, **debug** or **error**. It will be used to set the logger log level.
> - Add a **specificHeaders** configuration option. It takes a comma separated
> list of header names to include in the log message. By default it is empty.
> - Add a **specificAttributes** configuration option. It takes a comma
> separated list of attribute names to be included in the log message. By
> default it is empty.
> - **body** configuration option should be false by default
> - **header** configuration option should be false by default
> - **init** should propagate exception while initilizing (Integer parse
> exception, also passing a negative max body should throw.)
> - Remove inlined affectation for field. They can be unset on their
> declaration and set when init is called.
> Correct *LogMessageTest* accordingly.
> Don't hesitate to reach us on the *gitter* chat if you have any question.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]