summaryrefslogtreecommitdiffstats
path: root/gerrit-server/src/main/java/com/google/gerrit/server/mail/receive/MailMessage.java
blob: 68b3c23cd0c97f03f2ce07eb542a0ba6be1f25e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed 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 com.google.gerrit.server.mail.receive;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.server.mail.Address;
import org.joda.time.DateTime;

/**
 * A simplified representation of an RFC 2045-2047 mime email message used for representing received
 * emails inside Gerrit. It is populated by the MailParser after MailReceiver has received a
 * message. Transformations done by the parser include stitching mime parts together, transforming
 * all content to UTF-16 and removing attachments.
 *
 * <p>A valid {@link MailMessage} contains at least the following fields: id, from, to, subject and
 * dateReceived.
 */
@AutoValue
public abstract class MailMessage {
  // Unique Identifier
  public abstract String id();
  // Envelop Information
  public abstract Address from();

  public abstract ImmutableList<Address> to();

  public abstract ImmutableList<Address> cc();
  // Metadata
  public abstract DateTime dateReceived();

  public abstract ImmutableList<String> additionalHeaders();
  // Content
  public abstract String subject();

  @Nullable
  public abstract String textContent();

  @Nullable
  public abstract String htmlContent();
  // Raw content as received over the wire
  @Nullable
  public abstract ImmutableList<Integer> rawContent();

  @Nullable
  public abstract String rawContentUTF();

  public static Builder builder() {
    return new AutoValue_MailMessage.Builder();
  }

  public abstract Builder toBuilder();

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder id(String val);

    public abstract Builder from(Address val);

    public abstract ImmutableList.Builder<Address> toBuilder();

    public Builder addTo(Address val) {
      toBuilder().add(val);
      return this;
    }

    public abstract ImmutableList.Builder<Address> ccBuilder();

    public Builder addCc(Address val) {
      ccBuilder().add(val);
      return this;
    }

    public abstract Builder dateReceived(DateTime val);

    public abstract ImmutableList.Builder<String> additionalHeadersBuilder();

    public Builder addAdditionalHeader(String val) {
      additionalHeadersBuilder().add(val);
      return this;
    }

    public abstract Builder subject(String val);

    public abstract Builder textContent(String val);

    public abstract Builder htmlContent(String val);

    public abstract Builder rawContent(ImmutableList<Integer> val);

    public abstract Builder rawContentUTF(String val);

    public abstract MailMessage build();
  }
}