BrightSide Workbench Full Report + Source Code
MailRecipient.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.provider;
20 
21 import org.turro.plugin.contacts.IContact;
22 import org.turro.string.Strings;
23 
28 public class MailRecipient {
29 
30  private String name, mail;
31  private String friendly, formal;
32 
33  public String getName() {
34  return name;
35  }
36 
37  public void setName(String name) {
38  this.name = name;
39  }
40 
41  public String getMail() {
42  return mail;
43  }
44 
45  public void setMail(String mail) {
46  this.mail = mail;
47  }
48 
49  /* Utils */
50 
51  public boolean isEmpty() {
52  return Strings.isBlank(mail);
53  }
54 
55  /* Parse */
56 
57  public String parse(String text) {
58  if(!Strings.isBlank(mail)) {
59  text = text.replaceAll("\\{email\\}", mail);
60  }
61  if(!Strings.isBlank(name)) {
62  text = text.replaceAll("\\{name\\}", name);
63  }
64  if(!Strings.isBlank(friendly)) {
65  text = text.replaceAll("\\{friendly\\}", friendly);
66  }
67  if(!Strings.isBlank(formal)) {
68  text = text.replaceAll("\\{formal\\}", formal);
69  }
70  return text;
71  }
72 
73  /* Factory */
74 
75  public static MailRecipient of(String value) {
76  if(value != null) {
77  if(value.contains("|")) {
78  String[] parts = value.split("\\|");
79  return MailRecipient.of(parts[0], parts[1]);
80  }
81  }
82  return MailRecipient.of(value, null);
83  }
84 
85  public static MailRecipient of(String mail, String name) {
86  MailRecipient recipient = new MailRecipient();
87  recipient.mail = mail;
88  recipient.name = name;
89  recipient.formal = name;
90  recipient.friendly = name;
91  return recipient;
92  }
93 
94  public static MailRecipient of(IContact contact) {
95  MailRecipient recipient = new MailRecipient();
96  recipient.mail = contact.getEmail();
97  recipient.name = contact.getName();
98  recipient.formal = contact.getFormal();
99  recipient.friendly = contact.getFriendly();
100  return recipient;
101  }
102 
103 }
static MailRecipient of(String value)
static MailRecipient of(String mail, String name)
static MailRecipient of(IContact contact)