james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <server-...@james.apache.org>
Subject [jira] [Commented] (JAMES-992) Limit max line length for protocol when using Netty
Date Mon, 02 Oct 2017 06:23:00 GMT

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

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

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

    https://github.com/apache/james-project/pull/73#discussion_r142062712
  
    --- Diff: mailet/standard/src/main/java/org/apache/james/transport/matchers/HasMimeType.java
---
    @@ -0,0 +1,74 @@
    +/****************************************************************
    + * 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.matchers;
    +
    +import com.google.common.base.Splitter;
    +import com.google.common.collect.ImmutableSet;
    +import org.apache.james.core.MailAddress;
    +import org.apache.mailet.Mail;
    +import org.apache.mailet.base.GenericMatcher;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import javax.activation.MimeType;
    +import javax.activation.MimeTypeParseException;
    +import javax.mail.MessagingException;
    +import javax.mail.internet.MimeMessage;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.Set;
    +
    +
    +/**
    + * <p>This matcher checks if the content type matches.</p>
    + *
    + * use: <pre><code><mailet match="HasMimeType=text/plain,text/html" class="..."
/></code></pre>
    + */
    +public class HasMimeType extends GenericMatcher {
    +
    +    private static final Logger LOGGER = LoggerFactory.getLogger(HasHabeasWarrantMark.class);
    +
    +    private Set<String> contentType;
    +
    +    public void init() throws javax.mail.MessagingException {
    +        contentType = ImmutableSet.copyOf(Splitter.onPattern("\\s*,\\s*").split(getCondition()));
    +    }
    +
    +    public Collection<MailAddress> match(Mail mail) throws javax.mail.MessagingException
{
    +        String mimeType;
    +        mimeType = getMimeTypeFromMessage(mail.getMessage());
    +        if (contentType.contains(mimeType))
    +            return mail.getRecipients();
    +        else
    +            return Collections.emptyList();
    +    }
    +
    +    private static String getMimeTypeFromMessage(MimeMessage message) throws MessagingException
{
    +        try {
    +            return new MimeType(message.getContentType()).getBaseType();
    +        } catch (MimeTypeParseException e) {
    +            LOGGER.warn(e.toString());
    +            return "";
    --- End diff --
    
    If we return nothing, that has to be explicit on the type.
    
    The way we handle this in a clean way is using java Optional.
    
    You can then:
     - Modify the mimeType of this method to return Optional<String>
     - When returning something, return Optional.of(something)
     - When we encouter the error, we can then return Optional.empty()
     - Finally in **match** methods, we can handle the if resoluion in a functional manner
using *filter* and *orElse* (that might replace the if block)


> Limit max line length for protocol when using Netty
> ---------------------------------------------------
>
>                 Key: JAMES-992
>                 URL: https://issues.apache.org/jira/browse/JAMES-992
>             Project: James Server
>          Issue Type: Improvement
>            Reporter: Norman Maurer
>             Fix For: 3.0-M1
>
>
> We should limit the max characters per line so nobody can cause OOM when doing a DOS
attach



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

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


Mime
View raw message