Line data Source code
1 : // Copyright (C) 2016 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.mail; 16 : 17 : import com.google.auto.value.AutoValue; 18 : import com.google.common.collect.ImmutableList; 19 : import com.google.gerrit.common.Nullable; 20 : import com.google.gerrit.entities.Address; 21 : import java.time.Instant; 22 : 23 : /** 24 : * A simplified representation of an RFC 2045-2047 mime email message used for representing received 25 : * emails inside Gerrit. It is populated by the MailParser after MailReceiver has received a 26 : * message. Transformations done by the parser include stitching mime parts together, transforming 27 : * all content to UTF-16 and removing attachments. 28 : * 29 : * <p>A valid {@link MailMessage} contains at least the following fields: id, from, to, subject and 30 : * dateReceived. 31 : */ 32 : @AutoValue 33 6 : public abstract class MailMessage { 34 : // Unique Identifier 35 : public abstract String id(); 36 : // Envelop Information 37 : public abstract Address from(); 38 : 39 : public abstract ImmutableList<Address> to(); 40 : 41 : public abstract ImmutableList<Address> cc(); 42 : // Metadata 43 : public abstract Instant dateReceived(); 44 : 45 : public abstract ImmutableList<String> additionalHeaders(); 46 : // Content 47 : public abstract String subject(); 48 : 49 : @Nullable 50 : public abstract String textContent(); 51 : 52 : @Nullable 53 : public abstract String htmlContent(); 54 : // Raw content as received over the wire 55 : @Nullable 56 : public abstract ImmutableList<Integer> rawContent(); 57 : 58 : @Nullable 59 : public abstract String rawContentUTF(); 60 : 61 : public static Builder builder() { 62 6 : return new AutoValue_MailMessage.Builder(); 63 : } 64 : 65 : public abstract Builder toBuilder(); 66 : 67 : @AutoValue.Builder 68 6 : public abstract static class Builder { 69 : public abstract Builder id(String val); 70 : 71 : public abstract Builder from(Address val); 72 : 73 : public abstract ImmutableList.Builder<Address> toBuilder(); 74 : 75 : public Builder addTo(Address val) { 76 5 : toBuilder().add(val); 77 5 : return this; 78 : } 79 : 80 : public abstract ImmutableList.Builder<Address> ccBuilder(); 81 : 82 : public Builder addCc(Address val) { 83 1 : ccBuilder().add(val); 84 1 : return this; 85 : } 86 : 87 : public abstract Builder dateReceived(Instant instant); 88 : 89 : public abstract ImmutableList.Builder<String> additionalHeadersBuilder(); 90 : 91 : public Builder addAdditionalHeader(String val) { 92 3 : additionalHeadersBuilder().add(val); 93 3 : return this; 94 : } 95 : 96 : public abstract Builder subject(String val); 97 : 98 : public abstract Builder textContent(String val); 99 : 100 : public abstract Builder htmlContent(String val); 101 : 102 : public abstract Builder rawContent(ImmutableList<Integer> val); 103 : 104 : public abstract Builder rawContentUTF(String val); 105 : 106 : public abstract MailMessage build(); 107 : } 108 : }