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.mail; 16 : 17 : /** Variables used by emails to hold data */ 18 107 : public enum MailHeader { 19 : // Gerrit metadata holders 20 107 : ASSIGNEE("Gerrit-Assignee"), 21 107 : ATTENTION("Gerrit-Attention"), 22 107 : BRANCH("Gerrit-Branch"), 23 107 : CC("Gerrit-CC"), 24 107 : COMMENT_IN_REPLY_TO("Comment-In-Reply-To"), 25 107 : COMMENT_DATE("Gerrit-Comment-Date"), 26 107 : CHANGE_ID("Gerrit-Change-Id"), 27 107 : CHANGE_NUMBER("Gerrit-Change-Number"), 28 107 : CHANGE_URL("Gerrit-ChangeURL"), 29 107 : COMMIT("Gerrit-Commit"), 30 107 : HAS_COMMENTS("Gerrit-HasComments"), 31 107 : HAS_LABELS("Gerrit-Has-Labels"), 32 107 : MESSAGE_TYPE("Gerrit-MessageType"), 33 107 : OWNER("Gerrit-Owner"), 34 107 : PATCH_SET("Gerrit-PatchSet"), 35 107 : PROJECT("Gerrit-Project"), 36 107 : REVIEWER("Gerrit-Reviewer"), 37 : 38 : // Commonly used Email headers 39 107 : AUTO_SUBMITTED("Auto-Submitted"), 40 107 : PRECEDENCE("Precedence"), 41 107 : REFERENCES("References"); 42 : 43 : private final String name; 44 : private final String fieldName; 45 : 46 107 : MailHeader(String name) { 47 107 : boolean customHeader = name.startsWith("Gerrit-"); 48 107 : this.name = name; 49 : 50 107 : if (customHeader) { 51 107 : this.fieldName = "X-" + name; 52 : } else { 53 107 : this.fieldName = name; 54 : } 55 107 : } 56 : 57 : public String fieldWithDelimiter() { 58 3 : return fieldName() + ": "; 59 : } 60 : 61 : public String withDelimiter() { 62 107 : return name + ": "; 63 : } 64 : 65 : public String fieldName() { 66 107 : return fieldName; 67 : } 68 : 69 : public String getName() { 70 4 : return name; 71 : } 72 : }