[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-10 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Hi, I use an abstract method `log()` in the enum `LogLevel.class` 
and not introduce a new constructor and private field `LogWriter` to replace 
the `LogMessage::selectLogWriter` method, please have a check to see if it's 
okay to do in this way. Thanks!


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-10 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
> Hi.
> 
> The CI reported some checkstyle violation: could you have a look?
> 
> `[72cb939ae6d1174914f555ec461788ec2859135e] [ERROR] 
src/main/java/org/apache/mailet/MailetConfig.java:[24] (imports) 
CustomImportOrder: 'java.util.Iterator' should be separated from previous 
import group by one line.`

I fixed this checkstyle error in the newly pushed code.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Hi.

The CI reported some checkstyle violation: could you have a look?

`[72cb939ae6d1174914f555ec461788ec2859135e] [ERROR] 
src/main/java/org/apache/mailet/MailetConfig.java:[24] (imports) 
CustomImportOrder: 'java.util.Iterator' should be separated from previous 
import group by one line.`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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_r246622801
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -66,16 +79,20 @@ public LogMessage() {
 this(LOGGER);
 }
 
+
 @Override
 public void init() {
 try {
+logLevel = getInitParameter("level", LogLevel.class, 
LogLevel.INFO);
--- End diff --

I am amazed and very glad at the same time that this works!


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
For your information, I opened this PR for unit-testing & integration 
testing of this PR https://github.com/linagora/james-project/pull/2092


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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_r246622213
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -129,9 +165,33 @@ private int lengthToLog(MimeMessage message) throws 
MessagingException {
 
 private int messageSizeOrUnlimited(MimeMessage message) throws 
MessagingException {
 int computedSize = message.getSize();
-if (computedSize > 0) {
-return computedSize;
+return computedSize > 0 ? computedSize : Integer.MAX_VALUE;
+}
+
+private String logSpecificHeadersFor(Mail mail, MailAddress recipient) 
{
+StringBuilder headersLogs = new StringBuilder();
+List headers = 
mail.getPerRecipientSpecificHeaders()
+.getHeadersForRecipient(recipient).stream()
+.filter(header -> 
specificHeaderNames.contains(header.getName()))
+.collect(Collectors.toList());
+headersLogs.append("Recipient " + recipient.asPrettyString() + "'s 
headers are: \n");
+headersLogs.append(headers.stream().map(header -> header.getName() 
+ ": " + header.getValue()).collect(Collectors.joining("\n")));
+return headersLogs.toString();
+}
+
+private LogWriter selectLogWriter(LogLevel logLevel) {
+switch (logLevel) {
+case INFO:
+return (logger, message) -> logger.info(message);
+case WARN:
+return (logger, message) -> logger.warn(message);
+case DEBUG:
--- End diff --

Maybe we can put DEBUG before INFO to keep the implicit order


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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_r246622680
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogLevel.java 
---
@@ -0,0 +1,27 @@
+/
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information*
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the*
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *  *
+ *   http://www.apache.org/licenses/LICENSE-2.0 *
+ *  *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   *
+ * KIND, either express or implied.  See the License for the*
+ * specific language governing permissions and limitations  *
+ * under the License.   *
+ /
+package org.apache.james.transport.mailets;
+
+
+public enum LogLevel {
+DEBUG,
--- End diff --

Thinking about this we can enhance this rnum a lot by adding the LogWritter 
as a field:

```
public enum LogLevel {
Debug((logger, message) -> logger.debug(message)),
...;

private final LogWritter logWritter;

// Constructor & getter
}
```

That way we can no more need LogMessage::selectLogWriter


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
@ReturnHttp402 sure I will. Sorry it seems that I missed them.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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

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

https://github.com/apache/james-project/pull/145#discussion_r246619860
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -86,12 +103,27 @@ public String getMailetInfo() {
 
 @Override
 public void service(Mail mail) {
-logger.info("Logging mail {}", mail.getName());
-logComment();
+StringBuilder logs = new StringBuilder();
+logs.append(logComment());
 try {
-MimeMessage message = mail.getMessage();
-logHeaders(message);
-logBody(message);
+logs.append(logHeaders(mail) + logBody(mail) + 
logAttribute(mail));
+switch (logLevel) {
--- End diff --

 


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-09 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Hi, I've made some changes 6 days ago, can you help to check? 
Maybe we can introduce the automatic CI email alert when new changes are 
pushed. 


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Your comments are always very helpful and informative, I've 
learned a lot.Thanks!


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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_r245234684
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -86,12 +103,11 @@ public String getMailetInfo() {
 
 @Override
 public void service(Mail mail) {
-logger.info("Logging mail {}", mail.getName());
-logComment();
+StringBuilder logs = new StringBuilder();
+logs.append(logComment());
 try {
-MimeMessage message = mail.getMessage();
-logHeaders(message);
-logBody(message);
+logs.append(logHeaders(mail) + logBody(mail) + 
logAttribute(mail));
--- End diff --

We can avoid the string concatenation as we do have a string builder:

```
logs.append(logHeaders(mail));
logs.append(logBody(lail));
logs.append(logAttrribute(mail));
```


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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_r245234865
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,27 +116,45 @@ public void service(Mail mail) {
 }
 }
 
-private void logComment() {
-if (comment != null) {
-logger.info(comment);
+private String logAttribute(Mail mail) {
+StringBuilder attributeLog = new StringBuilder();
+if (!specificAttributeNames.isEmpty()) {
+for (String name : specificAttributeNames) {
+AttributeName attributeName = AttributeName.of(name);
+Optional attribute = 
mail.getAttribute(attributeName);
+attributeLog.append(name + ": " + 
attribute.map(Attribute::getValue).map(AttributeValue::getValue).get() + '\n');
+}
+return '\n' + attributeLog.toString();
 }
+return attributeLog.toString();
 }
 
-private void logHeaders(MimeMessage message) throws MessagingException 
{
+private String logComment() {
--- End diff --

This could be `commentLog`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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_r245235018
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,27 +116,45 @@ public void service(Mail mail) {
 }
 }
 
-private void logComment() {
-if (comment != null) {
-logger.info(comment);
+private String logAttribute(Mail mail) {
+StringBuilder attributeLog = new StringBuilder();
+if (!specificAttributeNames.isEmpty()) {
+for (String name : specificAttributeNames) {
+AttributeName attributeName = AttributeName.of(name);
+Optional attribute = 
mail.getAttribute(attributeName);
+attributeLog.append(name + ": " + 
attribute.map(Attribute::getValue).map(AttributeValue::getValue).get() + '\n');
+}
+return '\n' + attributeLog.toString();
 }
+return attributeLog.toString();
 }
 
-private void logHeaders(MimeMessage message) throws MessagingException 
{
+private String logComment() {
+return Optional.ofNullable(comment).orElse("");
+}
+
+private String logHeaders(Mail mail) throws MessagingException {
--- End diff --

This could be the `headersLog` method


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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_r245234919
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,27 +116,45 @@ public void service(Mail mail) {
 }
 }
 
-private void logComment() {
-if (comment != null) {
-logger.info(comment);
+private String logAttribute(Mail mail) {
+StringBuilder attributeLog = new StringBuilder();
+if (!specificAttributeNames.isEmpty()) {
+for (String name : specificAttributeNames) {
+AttributeName attributeName = AttributeName.of(name);
+Optional attribute = 
mail.getAttribute(attributeName);
+attributeLog.append(name + ": " + 
attribute.map(Attribute::getValue).map(AttributeValue::getValue).get() + '\n');
+}
+return '\n' + attributeLog.toString();
 }
+return attributeLog.toString();
 }
 
-private void logHeaders(MimeMessage message) throws MessagingException 
{
+private String logComment() {
+return Optional.ofNullable(comment).orElse("");
+}
+
+private String logHeaders(Mail mail) throws MessagingException {
+StringBuilder headersLog = new StringBuilder();
 if (headers && logger.isInfoEnabled()) {
-logger.info("\n");
-for (String header : 
Collections.list(message.getAllHeaderLines())) {
-logger.info(header + "\n");
+MimeMessage message = mail.getMessage();
+
headersLog.append(Collections.list(message.getAllHeaderLines()).stream().collect(Collectors.joining("\n")));
+
+if (!specificHeaderNames.isEmpty()) {
+headersLog.append("\n" + 
mail.getRecipients().stream().map(recipient -> logSpecificHeadersFor(mail, 
recipient)).collect(Collectors.joining("\n")));
 }
+return '\n' + headersLog.toString() + '\n';
 }
+return headersLog.toString();
 }
 
-private void logBody(MimeMessage message) throws MessagingException, 
IOException {
+private String logBody(Mail mail) throws MessagingException, 
IOException {
--- End diff --

This could be `bodyLog`


> 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: 

[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-04 Thread ASF GitHub Bot (JIRA)


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

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_r245234818
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,27 +116,45 @@ public void service(Mail mail) {
 }
 }
 
-private void logComment() {
-if (comment != null) {
-logger.info(comment);
+private String logAttribute(Mail mail) {
--- End diff --

While we are at it, we are not logging anything in this method hence I 
propose to name it `attributeLog`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Happy New Year


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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_r244935439
  
--- Diff: 
mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java ---
@@ -139,7 +156,7 @@ public String getInitParameter(String name) {
  * @param name - a String specifying the name of the initialization 
parameter
  * @param defValue - a String specifying the default value when the 
parameter
  *is not present
- * @return a String containing the value of the initalization parameter
+ * @return a generic type containing the value of the initialization 
parameter
--- End diff --

A string is returned, right?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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_r244937449
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -86,12 +103,27 @@ public String getMailetInfo() {
 
 @Override
 public void service(Mail mail) {
-logger.info("Logging mail {}", mail.getName());
-logComment();
+StringBuilder logs = new StringBuilder();
+logs.append(logComment());
 try {
-MimeMessage message = mail.getMessage();
-logHeaders(message);
-logBody(message);
+logs.append(logHeaders(mail) + logBody(mail) + 
logAttribute(mail));
+switch (logLevel) {
--- End diff --

I would suggest extracting this siwttch case to ease the reading of this 
method.

We can define a `LogWriter` interface: 

```
private interface LogWritter extends BiConsumer {}
```

Then a `selectLogWritter` method can be introduced:

```
private LogWritter selectlogWritter(LogLevel logLevel) {
switch(logLevel) {
case INFO:
return (logger, message) -> logger.info(message);
// etc..
}
}
```

The code here then become:

```
selectLogWritter(logLevel).apply(logger, logs.toString));
```

Rational: long methods is a code smell pointing out a piece of code have 
too much responsibilities.

Extracting shorter methods helps clearly dispatching these responsibilies.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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_r244935934
  
--- Diff: mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java 
---
@@ -96,19 +96,13 @@ public static String normalizeSubject(String subj, 
String prefix) {
  * Gets a boolean valued init parameter.
  * @param config not null
  * @param name name of the init parameter to be queried
- * @return true when the init parameter is true (ignoring 
case);
- * false when the init parameter is false (ignoring case);
+ * @return true when the init parameter is true;
+ * false when the init parameter is false;
+ * throw an exception when the value is not of Boolean type;
  * otherwise the default value
--- End diff --

otherwize returns empty


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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_r244935740
  
--- Diff: 
mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java ---
@@ -150,6 +167,28 @@ public String getInitParameter(String name, String 
defValue) {
 }
 }
 
+/**
+ * Returns a String containing the value of the named initialization
+ * parameter, or defValue if the parameter does not exist.
+ * 
+ * This method is supplied for convenience. It gets the value of the
+ * named parameter from the mailet's MailetConfig object.
+ *
+ * @param name - a String specifying the name of the initialization 
parameter
+ * @param clazz - a class type specifying the type of the returned 
value type
+ * @param defValue - a String specifying the default value when the 
parameter
+ *is not present
+ * @return a generic type containing the value of the initialization 
parameter
+ */
+public  T getInitParameter(String name, Class clazz, T defValue) 
{
+T res = config.getInitParameter(name, clazz);
+if (res == null) {
+return defValue;
+} else {
+return res;
+}
--- End diff --

This also can be written with an easy to read optional:

```
return Optional.ofNullable(config.getInitParameter(name, 
clazz)).orElse(defValue);
```


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-03 Thread ASF GitHub Bot (JIRA)


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

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_r244935798
  
--- Diff: 
mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java ---
@@ -150,6 +167,28 @@ public String getInitParameter(String name, String 
defValue) {
 }
 }
 
+/**
+ * Returns a String containing the value of the named initialization
+ * parameter, or defValue if the parameter does not exist.
+ * 
+ * This method is supplied for convenience. It gets the value of the
+ * named parameter from the mailet's MailetConfig object.
+ *
+ * @param name - a String specifying the name of the initialization 
parameter
+ * @param clazz - a class type specifying the type of the returned 
value type
+ * @param defValue - a String specifying the default value when the 
parameter
+ *is not present
+ * @return a generic type containing the value of the initialization 
parameter
+ */
+public  T getInitParameter(String name, Class clazz, T defValue) 
{
--- End diff --

I would prefer `defValue` to be `defaultValue`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
Hi @chibenwa I made some changes and squash my commits. Many thanks for 
your patient instructions


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Many thanks for your work ^^


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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_r244693254
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -23,18 +23,17 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.Optional;
+import java.util.Collections;
+import java.util.List;
 import java.util.stream.Collectors;
 
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.core.MailAddress;
-import org.apache.mailet.Attribute;
-import org.apache.mailet.AttributeName;
-import org.apache.mailet.Mail;
-import org.apache.mailet.PerRecipientHeaders;
+import org.apache.mailet.*;
--- End diff --

You introduced another wilcard here. Maybe you can change your IDE settings?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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_r244694584
  
--- Diff: 
mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
 ---
@@ -239,7 +243,7 @@ void serviceShouldNotLogHeadersWhenFalse() throws 
Exception {
 mailet.service(createMail());
 
 verify(logger).isInfoEnabled();
-verify(logger).info("This is a fake mail");
+verify(logger).info("\nThis is a fake mail");
--- End diff --

This `\\n` looks bad, no? Maybe we should avoid it?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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_r244693446
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -101,26 +97,25 @@ public String getMailetInfo() {
 
 @Override
 public void service(Mail mail) {
-logComment();
+String logs = "";
--- End diff --

Or we can use a stringBuilder here that we build at the end of the request 
to avoid variable re-allocation?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-02 Thread ASF GitHub Bot (JIRA)


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

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_r244693560
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -131,57 +126,45 @@ public void service(Mail mail) {
 }
 }
 
-private void logAttribute(Mail mail) {
+private String logAttribute(Mail mail) {
+String attributeLog = "";
 if (!specificAttributeNames.isEmpty()) {
-logBuffer.get().append('\n');
 for (String name : specificAttributeNames) {
 AttributeName attributeName = AttributeName.of(name);
 Optional attribute = 
mail.getAttribute(attributeName);
-if (attribute.isPresent()) {
-logBuffer.get().append(name + ": " + 
attribute.get().getValue().value() + '\n');
-} else {
-logBuffer.get().append(name + ": \n");
-}
+attributeLog += name + ": " + 
attribute.map(Attribute::getValue).map(AttributeValue::getValue).get() + '\n';
 }
+return '\n' + attributeLog;
 }
+return attributeLog;
 }
 
-private void logComment() {
-if (comment != null) {
-logBuffer.get().append(comment);
-}
+private String logComment() {
+return Optional.ofNullable(comment).orElse("");
 }
 
-private void logHeaders(Mail mail) throws MessagingException {
+private String logHeaders(Mail mail) throws MessagingException {
+String headersLog = "";
--- End diff --

Idem, we need to avoid variable re-allocation.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2019-01-01 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
Hi @chibenwa,
Thank you for your reviews and instructions, I followed your comments and 
made some changes.



> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282433
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
 ---
@@ -363,8 +363,8 @@ public void setPort(int port) {
  * Initializer for property maxPings.
  */
 protected void initMaxPings() {
-String maxPingsParam = getInitParameter("maxPings");
-setMaxPings((maxPingsParam == null) ? DEFAULT_MAX_PINGS : 
Integer.parseInt(maxPingsParam));
+Integer maxPingsParam = getInitParameter("maxPings", 
Integer.class);
+setMaxPings((maxPingsParam == null) ? DEFAULT_MAX_PINGS : 
maxPingsParam);
--- End diff --

If we are changing this code, then relying on Optional could be a good move.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Hi @ReturnHttp402 

I did an in depth review of the changeset you proposes.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244281702
  
--- Diff: mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java 
---
@@ -96,19 +96,19 @@ public static String normalizeSubject(String subj, 
String prefix) {
  * Gets a boolean valued init parameter.
  * @param config not null
  * @param name name of the init parameter to be queried
- * @return true when the init parameter is true (ignoring 
case);
- * false when the init parameter is false (ignoring case);
+ * @return true when the init parameter is true;
+ * false when the init parameter is false;
+ * throw an exception when the value is not of Boolean type;
  * otherwise the default value
  */
 public static Optional getInitParameter(MailetConfig config, 
String name) {
-String value = config.getInitParameter(name);
-if ("true".equalsIgnoreCase(value)) {
-return Optional.of(true);
+Object value = config.getInitParameter(name, Boolean.class);
--- End diff --

If we ask for a Boolean, then we got a Boolean, right? No need to type it 
as an object then cast it?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282448
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
 ---
@@ -394,8 +394,8 @@ public void setMaxPings(int maxPings) {
  * Initializer for property pingIntervalMilli.
  */
 protected void initPingIntervalMilli() {
-String pingIntervalMilliParam = 
getInitParameter("pingIntervalMilli");
-setPingIntervalMilli((pingIntervalMilliParam == null) ? 
DEFAULT_PING_INTERVAL_MILLI : Integer.parseInt(pingIntervalMilliParam));
+Integer pingIntervalMilliParam = 
getInitParameter("pingIntervalMilli", Integer.class);
+setPingIntervalMilli((pingIntervalMilliParam == null) ? 
DEFAULT_PING_INTERVAL_MILLI : pingIntervalMilliParam);
--- End diff --

If we are changing this code, then relying on Optional could be a good move.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244281998
  
--- Diff: mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java 
---
@@ -96,19 +96,19 @@ public static String normalizeSubject(String subj, 
String prefix) {
  * Gets a boolean valued init parameter.
  * @param config not null
  * @param name name of the init parameter to be queried
- * @return true when the init parameter is true (ignoring 
case);
- * false when the init parameter is false (ignoring case);
+ * @return true when the init parameter is true;
+ * false when the init parameter is false;
+ * throw an exception when the value is not of Boolean type;
  * otherwise the default value
  */
 public static Optional getInitParameter(MailetConfig config, 
String name) {
-String value = config.getInitParameter(name);
-if ("true".equalsIgnoreCase(value)) {
-return Optional.of(true);
+Object value = config.getInitParameter(name, Boolean.class);
--- End diff --

Moreover the entire point of using `Optional` is to not deal with null 
checks.

I bet this code snipset could actually be as simple as: 

```
return Optional.ofNullable(config.getInitParameter(name, Boolean.class));
```


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283971
  
--- 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 = 
mail.getAttribute(attributeName);
+if (attribute.isPresent()) {
--- End diff --

This condition defeat the use of Optional, which should be used as a 
monad...

```
logBuffer.get().append(name + ": " + 
attribute.map(Attribute::getValue).map(AttributeValue::value) + "\n");
```


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282584
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -18,19 +18,23 @@
  /
 
 
-
 package org.apache.james.transport.mailets;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.Collections;
+import java.util.*;
--- End diff --

This wilcard import will be rejected by our checkrule


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244281487
  
--- Diff: 
mailet/base/src/main/java/org/apache/mailet/base/GenericMailet.java ---
@@ -88,8 +88,9 @@ public boolean getInitParameter(String name, boolean 
defaultValue) {
 return MailetUtil.getInitParameter(config, 
name).orElse(defaultValue);
 }
 
+
 public Optional getInitParameterAsOptional(String name) {
-String value = getInitParameter(name);
+String value = getInitParameter(name, String.class);
--- End diff --

`String value = getInitParameter(name);`

Should be enough, no?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282358
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
 ---
@@ -332,8 +332,8 @@ public void setHost(String host) throws 
UnknownHostException {
  * Initializer for property port.
  */
 protected void initPort() {
-String portParam = getInitParameter("port");
-setPort((portParam == null) ? DEFAULT_PORT : 
Integer.parseInt(portParam));
+Integer portParam = getInitParameter("port", Integer.class);
+setPort((portParam == null) ? DEFAULT_PORT : portParam);
--- End diff --

Idem this could be handled with an Optional...


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283656
  
--- Diff: 
mailet/test/src/main/java/org/apache/mailet/base/test/FakeMailetConfig.java ---
@@ -76,22 +74,33 @@ public FakeMailetConfig build() {
 
 private final String mailetName;
 private final MailetContext mailetContext;
-private final Properties properties;
+private final Map properties;
 
-private FakeMailetConfig(String mailetName, MailetContext 
mailetContext, Properties properties) {
+private FakeMailetConfig(String mailetName, MailetContext 
mailetContext, Map properties) {
 this.mailetName = mailetName;
 this.mailetContext = mailetContext;
 this.properties = properties;
 }
 
+@Override
+public  T getInitParameter(String name, Class clazz) {
+Object o = properties.get(name);
+if (o != null) {
+if (clazz.isInstance(o)) {
+return (T) properties.get(name);
+} else throw new ClassCastException(name + " property is not 
of type " + clazz.getCanonicalName());
+} else return null;
--- End diff --

You need an explicit `{}` block


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283505
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/WrapText.java 
---
@@ -48,7 +48,7 @@ public String getMailetInfo() {
 @Override
 public void init() throws MailetException {
 optionFlowedDelsp = 
getBooleanParameter(getInitParameter(PARAMETER_NAME_FLOWED_DELSP), 
optionFlowedDelsp);
-optionWidth = 
Integer.parseInt(getInitParameter(PARAMETER_NAME_WIDTH, "" + optionWidth));
+optionWidth = getInitParameter(PARAMETER_NAME_WIDTH,Integer.class, 
optionWidth);
--- End diff --

You miss a space before `,Integer.class`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282504
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClassifyBounce.java
 ---
@@ -54,7 +54,7 @@
 
 @Override
 public void init() throws MessagingException {
-headerName = getInitParameter("headerName");
+headerName = getInitParameter("headerName", String.class);
--- End diff --

Isn't `headerName = getInitParameter("headerName");` enough?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282457
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
 ---
@@ -425,8 +425,8 @@ public void setPingIntervalMilli(int pingIntervalMilli) 
{
  * Initializer for property streamBufferSize.
  */
 protected void initStreamBufferSize() {
-String streamBufferSizeParam = 
getInitParameter("streamBufferSize");
-setStreamBufferSize((streamBufferSizeParam == null) ? 
DEFAULT_STREAM_BUFFER_SIZE : Integer.parseInt(streamBufferSizeParam));
+Integer streamBufferSizeParam = 
getInitParameter("streamBufferSize", Integer.class);
+setStreamBufferSize((streamBufferSizeParam == null) ? 
DEFAULT_STREAM_BUFFER_SIZE : streamBufferSizeParam);
--- End diff --

If we are changing this code, then relying on Optional could be a good move.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244284235
  
--- 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 = 
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 headers = 
mail.getPerRecipientSpecificHeaders()
--- End diff --

Can we extect line 165 to 172 in a dedicated `logSpecificHeadersFor(Mail 
mail, MailAddress recipient)` method?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283550
  
--- Diff: 
mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
 ---
@@ -31,16 +32,22 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
+import org.apache.james.core.MailAddress;
 import org.apache.james.core.builder.MimeMessageBuilder;
 import org.apache.james.util.MimeMessageUtil;
-import org.apache.mailet.Mail;
+import org.apache.mailet.*;
--- End diff --

This WILCARD will brake MVN compilation


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283374
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java
 ---
@@ -114,7 +114,7 @@ public void init() throws MailetException {
 }
 
 private boolean isDebug() {
-return Integer.valueOf(getInitParameter("debug", "0")) == 1;
+return getInitParameter("debug", false);
--- End diff --

That, is an API change. You will break peoples ReplaceContent debug 
configuration as the `1` value (which I agree is not explicit at all) will be 
broken.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283449
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/UseHeaderRecipients.java
 ---
@@ -84,7 +84,7 @@
  */
 @Override
 public void init() {
-isDebug = (getInitParameter("debug") == null) ? false : 
Boolean.valueOf(getInitParameter("debug"));
+isDebug = (getInitParameter("debug", Boolean.class) == null) ? 
false : getInitParameter("debug", Boolean.class);
--- End diff --

If we modify this changeset, then we could give a try to  using Optional 
here


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/JAMES-2171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=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 = 
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 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 

[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244281616
  
--- Diff: mailet/base/src/main/java/org/apache/mailet/base/MailetUtil.java 
---
@@ -96,19 +96,19 @@ public static String normalizeSubject(String subj, 
String prefix) {
  * Gets a boolean valued init parameter.
  * @param config not null
  * @param name name of the init parameter to be queried
- * @return true when the init parameter is true (ignoring 
case);
- * false when the init parameter is false (ignoring case);
+ * @return true when the init parameter is true;
+ * false when the init parameter is false;
+ * throw an exception when the value is not of Boolean type;
  * otherwise the default value
  */
 public static Optional getInitParameter(MailetConfig config, 
String name) {
-String value = config.getInitParameter(name);
-if ("true".equalsIgnoreCase(value)) {
-return Optional.of(true);
+Object value = config.getInitParameter(name, Boolean.class);
+if(value != null){
+if(Boolean.class.isInstance(value)){
+return Optional.of((Boolean)value);
+} else throw new ClassCastException(name + " property is not 
of type " + Boolean.class);
 }
-if ("false".equalsIgnoreCase(value)) {
-return Optional.of(false);
-}
-return Optional.empty();
+else return Optional.empty();
--- End diff --

This will probably not pass the checkstyle rules. You need to explicitly 
define blocks of code using `{}`


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282295
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/ClamAVScan.java
 ---
@@ -266,8 +266,8 @@ public String getMailetInfo() {
  * Initializer for property debug.
  */
 protected void initDebug() {
-String debugParam = getInitParameter("debug");
-setDebug((debugParam == null) ? false : 
Boolean.valueOf(debugParam));
+Boolean debugParam = getInitParameter("debug", Boolean.class);
+setDebug((debugParam == null) ? false : debugParam);
--- End diff --

This can be `Optional.ofNullable(debugParam).orElse(false)` which would be 
more functional friendly and more readable.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244283131
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -52,11 +56,17 @@
  * or mark it as finished.
  */
 private final Logger logger;
+private LogLevel logLevel;
 private boolean passThrough = true;
-private boolean headers = true;
-private boolean body = true;
-private int bodyMax = 0;
-private String comment = null;
+private boolean headers;
+private boolean body;
+private int bodyMax;
+private String comment;
+private List specificHeaderNames;
+private List specificAttributeNames;
+
+//private StringBuffer logBuffer = new StringBuffer();
+private ThreadLocal logBuffer = new ThreadLocal<>();
--- End diff --

Or I am really not confortable with statefull mailet.

Maybe a better way of seeing things is that each `log*` method return a 
String (representing logParts) that gets then concatenated together & logged.

Mutability makes reasoning about programming hard. We tend to prefer 
predictable pure function...


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282122
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java 
---
@@ -146,9 +146,9 @@ private String attachFooterToHTML(String content) 
throws MessagingException,
 }
 int insertionIndex = matcher.start(matcher.groupCount() - 1);
 return new StringBuilder()
-.append(content.substring(0, insertionIndex))
+.append(content, 0, insertionIndex)
--- End diff --

`.append(content.substring(0, insertionIndex))` was IMO more explicit


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-28 Thread ASF GitHub Bot (JIRA)


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

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_r244282652
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -66,16 +76,21 @@ public LogMessage() {
 this(LOGGER);
 }
 
+
 @Override
 public void init() {
 try {
+logBuffer.set(new StringBuilder());
+logLevel = getInitParameter("level", LogLevel.class, 
LogLevel.INFO);
+specificHeaderNames = getInitParameter("specificHeaders", 
List.class, Collections.emptyList());
+specificAttributeNames = 
getInitParameter("specificAttributes", List.class, Collections.emptyList());
+headers = getInitParameter("headers", false);
+body = getInitParameter("body", false);
 passThrough = getInitParameter("passThrough", true);
-headers = getInitParameter("headers", true);
-body = getInitParameter("body", true);
-bodyMax = (getInitParameter("maxBody") == null) ? 0 : 
Integer.parseInt(getInitParameter("maxBody"));
+bodyMax = (getInitParameter("maxBody", Integer.class) == null) 
? 0 : getInitParameter("maxBody", Integer.class);
--- End diff --

Can we use Optional ?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-27 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Hi, I add back the former string version api and pickup only my 
commits and do the rebase, I suspect that other unrelated commits may come from 
the CI process.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-20 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Also can you rebase your PR on master? I see a lot of non related commits 
in github...


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-20 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Hi @ReturnHttp402 

I mean we could have both:

```
 T getInitParameter(String name, Class clazz) throws 
ClassCastException;

String getInitParameter(String name);
```

That way nothing changes if I want a String. If I want *something else*, I 
can use the new method


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-20 Thread ASF GitHub Bot (JIRA)


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

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_r243482572
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -38,17 +38,19 @@
  * or null if the parameter does not exist.
  *
  * @param name the name of the initialization parameter
+ * @param clazz the type of the returned value
  * @return the value of the initialization parameter, or null
+ * @throws ClassCastException
  */
-String getInitParameter(String name);
--- End diff --

IMO we should keep the `String getInitParameter(String name);` method as it 
is more convenient most of the time...


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-18 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Hi, Sorry for the long-delayed reply, I've been fixing my PC 
recently, I have one question about your last comment on 'String' version, do 
you mean using the previous explicit type casting?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-18 Thread ASF GitHub Bot (JIRA)


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

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

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

https://github.com/apache/james-project/pull/145#discussion_r242486369
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java 
---
@@ -53,7 +53,7 @@
 
 @Override
 public void init() throws MessagingException {
-plainTextFooter = (String) 
getInitParameter(MailetConfiguration.TEXT.name());
+plainTextFooter = getInitParameter("text", String.class);
--- End diff --

You mean the explicit type casting version? I think it's redundant here 
because using generics can help us to do the auto casting job. 


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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_r241667572
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/AddFooter.java 
---
@@ -53,7 +53,7 @@
 
 @Override
 public void init() throws MessagingException {
-plainTextFooter = (String) 
getInitParameter(MailetConfiguration.TEXT.name());
+plainTextFooter = getInitParameter("text", String.class);
--- End diff --

Why don't we 'stick' with the previous String version, that is directly the 
type that we want?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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_r241667599
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/AddSubjectPrefix.java
 ---
@@ -46,7 +46,7 @@
 
 @Override
 public void init() throws MessagingException {
-subjectPrefix = (String) 
getInitParameter(MailetConfiguration.SUBJECT_PREFIX.name());
+subjectPrefix = getInitParameter("subjectPrefix", String.class);
--- End diff --

Why don't we 'stick' with the previous String version, that is directly the 
type that we want?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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_r241668080
  
--- Diff: 
mailet/standard/src/test/java/org/apache/james/transport/mailets/LogMessageTest.java
 ---
@@ -352,4 +354,11 @@ private FakeMail createMail() throws 
MessagingException {
 .build();
 }
 
+@Test
+public void test() {
--- End diff --

This "debug" tests is valuable. Can we do a real assertion for it?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Thanks for your comments, it's very helpful, I've made some 
changes, can you review it again?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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_r241311997
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

Well, this method needs to be implemented in MailetConfig & 
MailetConfigImpl, then GenericMailet only needs to be calling that:

```
@Override
public  T getInitParameter(String name, Class clazz) throws 
ClassCastException {
return getMailetConfig().getInitParameter(name, clazz);
}
```

For the record, in MailetConfigImpl, this could look like this: 

```
@Override
public  T getInitParameter(String name, Class clazz) throws 
ClassCastException {
Object o = configuration.getProperty(name);
if (clazz.isInstance(o)) {
return (T) o;
}
throw new ClassCastException(name + " property is not of type " + 
clazz.getCanonicalName());
}
```

Would this seems Ok to you?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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

Github user chibenwa commented on the issue:

https://github.com/apache/james-project/pull/145
  
Well, this method needs to be implemented in MailetConfig & 
MailetConfigImpl, then GenericMailet only needs to be calling that:

```
@Override
public  T getInitParameter(String name, Class clazz) throws 
ClassCastException {
return getMailetConfig().getInitParameter(name, clazz);
}
```

For the record, in MailetConfigImpl, this could look like this: 

```
@Override
public  T getInitParameter(String name, Class clazz) throws 
ClassCastException {
Object o = configuration.getProperty(name);
if (clazz.isInstance(o)) {
return (T) o;
}
throw new ClassCastException(name + " property is not of type " + 
clazz.getCanonicalName());
}
```

Would this seems Ok to you?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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

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

https://github.com/apache/james-project/pull/145#discussion_r241309841
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

In `GenericMailet` it calls the` getInitParameter` in the `MailetConfig`, 
however, when added the parameter `Class clazz`, there's something needed to 
be passed in or construct when calling the method, I don't know what to pass 
here.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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_r241306507
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

> Is the Class clazz in the getInitParameter used to indicate the data 
type for the returned value to improve API discovery?

Yes that is my proposal here.

> If yes, what supposed to fill in the config.getInitParameter(name, ) used 
in the method getInitParameter in class GenericMailet

Do we need to change these methods?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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

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

https://github.com/apache/james-project/pull/145#discussion_r241305344
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

The reason that I use the enum version is that I think using String might 
cause problems when fill string with different cases by mistake, but anyway, 
I'll roll the related code back.


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-13 Thread ASF GitHub Bot (JIRA)


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

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

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

https://github.com/apache/james-project/pull/145#discussion_r241304224
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

Is the `Class clazz` in the `getInitParameter` used to indicate the data 
type for the returned value to improve API discovery? If yes, what supposed to 
fill in the `config.getInitParameter(name, )` used in the method 
`getInitParameter` in class `GenericMailet`?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-12 Thread ASF GitHub Bot (JIRA)


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

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_r241293360
  
--- Diff: mailet/api/src/main/java/org/apache/mailet/MailetConfig.java ---
@@ -40,7 +41,7 @@
  * @param name the name of the initialization parameter
  * @return the value of the initialization parameter, or null
  */
-String getInitParameter(String name);
+Object getInitParameter(String name);
--- End diff --

I tend to strongly believe strong typing is a nice property to have, as it 
enables compile time checks and improves safety + efficiency. It also improves 
API discovery, which is actually quite critical in an API that is the base of 
James extension model.

We should refrain from changing any API related to mailets.

That being said, maybe we can add a : 

```
 T getInitParameter(String name, Class clazz) throws 
ClassCastException;
```

Might be a good idea, as it might allow the caller to avoid some job 
parsing strings.

Note that this method returns always the right type, which is now decided 
by the caller (and not by the underlying datatype).

Also, I would be in favor to keep the 'old' code using the previous 
'String' version


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-12 Thread ASF GitHub Bot (JIRA)


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

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

Github user ReturnHttp402 commented on the issue:

https://github.com/apache/james-project/pull/145
  
@chibenwa Hi I made a few changes and I'm not sure if this is a best 
practice to use type casting, please have a check, thanks!


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240500514
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,25 +187,39 @@ public void service(Mail mail) {
 }
 }
 
+private void logAttribute(List specificAttributes) {
+if(!specificAttributes.isEmpty()){
+logBuffer.append('\n');
+for(String attribute : specificAttributes){
+logBuffer.append(attribute + '\n');
+}
+}
+}
+
 private void logComment() {
 if (comment != null) {
-logger.info(comment);
+logBuffer.append(comment);
 }
 }
 
 private void logHeaders(MimeMessage message) throws MessagingException 
{
 if (headers && logger.isInfoEnabled()) {
-logger.info("\n");
+logBuffer.append('\n');
 for (String header : 
Collections.list(message.getAllHeaderLines())) {
-logger.info(header + "\n");
+logBuffer.append(header + '\n');
+}
+if(!specificHeaders.isEmpty()){
+for(String header : specificHeaders){
--- End diff --

Don't we need to read mail.perRecipientHeaders here rather than only 
listing configured header names?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240500049
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -86,12 +155,30 @@ public String getMailetInfo() {
 
 @Override
 public void service(Mail mail) {
-logger.info("Logging mail {}", mail.getName());
+//logger.info("Logging mail {}", mail.getName());
--- End diff --

Can this comment be removed?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240499957
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -73,9 +136,15 @@ public void init() {
 headers = getInitParameter("headers", true);
 body = getInitParameter("body", true);
 bodyMax = (getInitParameter("maxBody") == null) ? 0 : 
Integer.parseInt(getInitParameter("maxBody"));
+if(bodyMax < 0){
+logger.error("Parsed a negative maxBody value and caused 
initialization failure");
+throw new IllegalArgumentException("The value of maxBody 
cannot be negative.");
+}
 comment = getInitParameter("comment");
-} catch (Exception e) {
-logger.error("Caught exception while initializing LogMessage", 
e);
+} catch (NumberFormatException e){
+logger.error("Caught exception while parsing maxBody value", 
e);
--- End diff --

I would argue that we don't want to start with an invalid configuration. 
Maybe catching these exceptions is not needed?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240498913
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -52,18 +52,81 @@
  * or mark it as finished.
  */
 private final Logger logger;
+private final LogLevel logLevel;
 private boolean passThrough = true;
-private boolean headers = true;
-private boolean body = true;
-private int bodyMax = 0;
-private String comment = null;
+private boolean headers;
+private boolean body;
+private int bodyMax;
+private String comment;
+private List specificHeaders;
+private List specificAttributes;
+
+private StringBuffer logBuffer = new StringBuffer();
--- End diff --

Please consider that mailet are concurrently called. Your code needs to be 
safe in a multi-threaded context.

Hence sharing a buffer seems 'unsafe'


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240500292
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -100,25 +187,39 @@ public void service(Mail mail) {
 }
 }
 
+private void logAttribute(List specificAttributes) {
+if(!specificAttributes.isEmpty()){
+logBuffer.append('\n');
+for(String attribute : specificAttributes){
--- End diff --

Don't we need to read these specific attributes from the email rather than 
just log the configured value?


> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread ASF GitHub Bot (JIRA)


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

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_r240499676
  
--- Diff: 
mailet/standard/src/main/java/org/apache/james/transport/mailets/LogMessage.java
 ---
@@ -52,18 +52,81 @@
  * or mark it as finished.
  */
 private final Logger logger;
+private final LogLevel logLevel;
 private boolean passThrough = true;
-private boolean headers = true;
-private boolean body = true;
-private int bodyMax = 0;
-private String comment = null;
+private boolean headers;
+private boolean body;
+private int bodyMax;
+private String comment;
+private List specificHeaders;
+private List specificAttributes;
+
+private StringBuffer logBuffer = new StringBuffer();
+
+
+public static Builder builder() {
+return new Builder();
+}
+
+public static class Builder {
+private Logger logger;
+private List specificHeaders;
+private List specificAttributes;
+private boolean headers;
+private boolean body;
+private LogLevel logLevel;
+
+private Builder(){
+logger = LOGGER;
+specificHeaders = new LinkedList<>();
+specificAttributes = new LinkedList<>();
+body = false;
+headers = false;
+}
+
+public Builder logger(final Logger logger) {
+this.logger = logger;
+return this;
+}
+
+public Builder logLevel(final LogLevel logLevel) {
+this.logLevel = logLevel;
+return this;
+}
+
+public Builder specificHeaders(List headers) {
+this.specificHeaders.addAll(headers);
+return this;
+}
+
+public Builder specificAttributes(List attributes) {
+this.specificAttributes.addAll(attributes);
+return this;
+}
+
+public Builder hasHeaders(boolean headers) {
+this.headers = headers;
+return this;
+}
+
+public Builder hasBody(boolean body) {
+this.body = body;
+return this;
+}
+
+public LogMessage build(){
+return new 
LogMessage(logger,logLevel,specificHeaders,specificAttributes,headers,body);
+}
 
-public LogMessage(Logger logger) {
-this.logger = logger;
 }
 
-public LogMessage() {
-this(LOGGER);
+private LogMessage(Logger logger, LogLevel logLevel, List 
specificHeaders, List specificAttributes, boolean headers, boolean 
body){
--- End diff --

While having a builder is clearly valuable, James needs to be able to 
'inject' fields in that mailet.

So, we need to read the LogLevel, specificHeaders, specificAttributes 
headers & body parameters from the configuration, in the `init` method.


> 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 

[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2018-12-10 Thread Yolanda Tang (JIRA)


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

Yolanda Tang commented on JAMES-2171:
-

I have raised a pull request https://github.com/apache/james-project/pull/145

> 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: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



[jira] [Commented] (JAMES-2171) LogMessage mailet improvments

2017-11-26 Thread JIRA

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

Rafał Byczek commented on JAMES-2171:
-

Can I do this task?

> 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
>  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
(v6.4.14#64029)

-
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org