BrightSide Workbench Full Report + Source Code
Recipient.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.mail.impl;
20 
21 import org.turro.plugin.contacts.IContact;
22 import org.turro.string.Strings;
23 
28 @Deprecated
29 public class Recipient {
30 
31  public Recipient friendly(String friendly) {
32  this.friendly = friendly;
33  return this;
34  }
35 
36  public Recipient formal(String formal) {
37  this.formal = formal;
38  return this;
39  }
40 
41  public String getEmail() {
42  return email;
43  }
44 
45  public String getName() {
46  return name;
47  }
48 
49  public String getFriendly() {
50  return friendly;
51  }
52 
53  public String getFormal() {
54  return formal;
55  }
56 
57  public boolean isEmpty() {
58  return Strings.isBlank(email);
59  }
60 
61  /* Parse */
62 
63  public String parse(String text) {
64  if(!Strings.isBlank(email)) {
65  text = text.replaceAll("\\{email\\}", email);
66  }
67  if(!Strings.isBlank(name)) {
68  text = text.replaceAll("\\{name\\}", name);
69  }
70  if(!Strings.isBlank(friendly)) {
71  text = text.replaceAll("\\{friendly\\}", friendly);
72  }
73  if(!Strings.isBlank(formal)) {
74  text = text.replaceAll("\\{formal\\}", formal);
75  }
76  return text;
77  }
78 
79  /* Factory */
80 
81  public static Recipient of(IContact contact) {
82  return Recipient.of(contact.getEmail(), contact.getName())
83  .friendly(contact.getFriendly())
84  .formal(contact.getFormal());
85  }
86 
87  public static Recipient of(String email, String name) {
88  return new Recipient(email, name);
89  }
90 
91  private final String email, name;
92  private String friendly, formal;
93 
94  private Recipient(String email, String name) {
95  this.email = email;
96  this.name = name;
97  }
98 
99 }
static Recipient of(IContact contact)
Definition: Recipient.java:81
Recipient friendly(String friendly)
Definition: Recipient.java:31
Recipient formal(String formal)
Definition: Recipient.java:36
static Recipient of(String email, String name)
Definition: Recipient.java:87
String parse(String text)
Definition: Recipient.java:63