Line data Source code
1 : // Copyright (C) 2009 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.send; 16 : 17 : import com.google.gerrit.common.Nullable; 18 : import com.google.gerrit.entities.Address; 19 : import com.google.gerrit.entities.EmailHeader; 20 : import com.google.gerrit.exceptions.EmailException; 21 : import java.util.Collection; 22 : import java.util.Map; 23 : 24 : /** Sends email messages to third parties. */ 25 : public interface EmailSender { 26 : boolean isEnabled(); 27 : 28 : /** 29 : * Can the address receive messages from us? 30 : * 31 : * @param address the address to consider. 32 : * @return true if this sender will deliver to the address. 33 : */ 34 : boolean canEmail(String address); 35 : 36 : /** 37 : * Sends an email message. Messages always contain a text body, but messages can optionally 38 : * include an additional HTML body. If both body types are present, {@code send} should construct 39 : * a {@code multipart/alternative} message with an appropriately-selected boundary. 40 : * 41 : * @param from who the message is from. 42 : * @param rcpt one or more address where the message will be delivered to. This list overrides any 43 : * To or CC headers in {@code headers}. 44 : * @param headers message headers. 45 : * @param textBody text to appear in the {@code text/plain} body of the message. 46 : * @param htmlBody optional HTML code to appear in the {@code text/html} body of the message. 47 : * @throws EmailException the message cannot be sent. 48 : */ 49 : default void send( 50 : Address from, 51 : Collection<Address> rcpt, 52 : Map<String, EmailHeader> headers, 53 : String textBody, 54 : @Nullable String htmlBody) 55 : throws EmailException { 56 0 : send(from, rcpt, headers, textBody); 57 0 : } 58 : 59 : /** 60 : * Sends an email message with a text body only (i.e. not HTML or multipart). 61 : * 62 : * <p>Authors of new implementations of this interface should not use this method to send a 63 : * message because this method does not accept the HTML body. Instead, authors should use the 64 : * above signature of {@code send}. 65 : * 66 : * <p>This version of the method is preserved for support of legacy implementations. 67 : * 68 : * @param from who the message is from. 69 : * @param rcpt one or more address where the message will be delivered to. This list overrides any 70 : * To or CC headers in {@code headers}. 71 : * @param headers message headers. 72 : * @param body text to appear in the body of the message. 73 : * @throws EmailException the message cannot be sent. 74 : */ 75 : void send(Address from, Collection<Address> rcpt, Map<String, EmailHeader> headers, String body) 76 : throws EmailException; 77 : }