LCOV - code coverage report
Current view: top level - server/mail - AutoReplyMailFilter.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 18 18 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2018 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.mail;
      16             : 
      17             : import com.google.common.flogger.FluentLogger;
      18             : import com.google.gerrit.mail.MailHeader;
      19             : import com.google.gerrit.mail.MailMessage;
      20             : import com.google.inject.Singleton;
      21             : 
      22             : /** Filters out auto-reply messages according to RFC 3834. */
      23             : @Singleton
      24         139 : public class AutoReplyMailFilter implements MailFilter {
      25         139 :   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
      26             : 
      27             :   @Override
      28             :   public boolean shouldProcessMessage(MailMessage message) {
      29           1 :     for (String header : message.additionalHeaders()) {
      30           1 :       if (header.startsWith(MailHeader.PRECEDENCE.fieldWithDelimiter())) {
      31           1 :         String prec = header.substring(MailHeader.PRECEDENCE.fieldWithDelimiter().length()).trim();
      32             : 
      33           1 :         if (prec.equals("list") || prec.equals("junk") || prec.equals("bulk")) {
      34           1 :           logger.atSevere().log(
      35           1 :               "Message %s has a Precedence header. Will ignore and delete message.", message.id());
      36           1 :           return false;
      37             :         }
      38             : 
      39           1 :       } else if (header.startsWith(MailHeader.AUTO_SUBMITTED.fieldWithDelimiter())) {
      40           1 :         String autoSubmitted =
      41           1 :             header.substring(MailHeader.AUTO_SUBMITTED.fieldWithDelimiter().length()).trim();
      42             : 
      43           1 :         if (!autoSubmitted.equals("no")) {
      44           1 :           logger.atSevere().log(
      45             :               "Message %s has an Auto-Submitted header. Will ignore and delete message.",
      46           1 :               message.id());
      47           1 :           return false;
      48             :         }
      49             :       }
      50           1 :     }
      51             : 
      52           1 :     return true;
      53             :   }
      54             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750