1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.smtp;
17
18 import io.netty.util.AsciiString;
19 import io.netty.util.internal.ObjectUtil;
20 import io.netty.util.internal.UnstableApi;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25
26
27
28
29 @UnstableApi
30 public final class SmtpRequests {
31
32 private static final SmtpRequest DATA = new DefaultSmtpRequest(SmtpCommand.DATA);
33 private static final SmtpRequest NOOP = new DefaultSmtpRequest(SmtpCommand.NOOP);
34 private static final SmtpRequest RSET = new DefaultSmtpRequest(SmtpCommand.RSET);
35 private static final SmtpRequest HELP_NO_ARG = new DefaultSmtpRequest(SmtpCommand.HELP);
36 private static final SmtpRequest QUIT = new DefaultSmtpRequest(SmtpCommand.QUIT);
37 private static final AsciiString FROM_NULL_SENDER = AsciiString.cached("FROM:<>");
38
39
40
41
42 public static SmtpRequest helo(CharSequence hostname) {
43 return new DefaultSmtpRequest(SmtpCommand.HELO, hostname);
44 }
45
46
47
48
49 public static SmtpRequest ehlo(CharSequence hostname) {
50 return new DefaultSmtpRequest(SmtpCommand.EHLO, hostname);
51 }
52
53
54
55
56 public static SmtpRequest empty(CharSequence... parameter) {
57 return new DefaultSmtpRequest(SmtpCommand.EMPTY, parameter);
58 }
59
60
61
62
63 public static SmtpRequest auth(CharSequence... parameter) {
64 return new DefaultSmtpRequest(SmtpCommand.AUTH, parameter);
65 }
66
67
68
69
70 public static SmtpRequest noop() {
71 return NOOP;
72 }
73
74
75
76
77 public static SmtpRequest data() {
78 return DATA;
79 }
80
81
82
83
84 public static SmtpRequest rset() {
85 return RSET;
86 }
87
88
89
90
91 public static SmtpRequest help(String cmd) {
92 return cmd == null ? HELP_NO_ARG : new DefaultSmtpRequest(SmtpCommand.HELP, cmd);
93 }
94
95
96
97
98 public static SmtpRequest quit() {
99 return QUIT;
100 }
101
102
103
104
105 public static SmtpRequest mail(CharSequence sender, CharSequence... mailParameters) {
106 if (mailParameters == null || mailParameters.length == 0) {
107 return new DefaultSmtpRequest(SmtpCommand.MAIL,
108 sender != null ? "FROM:<" + sender + '>' : FROM_NULL_SENDER);
109 } else {
110 List<CharSequence> params = new ArrayList<CharSequence>(mailParameters.length + 1);
111 params.add(sender != null? "FROM:<" + sender + '>' : FROM_NULL_SENDER);
112 Collections.addAll(params, mailParameters);
113 return new DefaultSmtpRequest(SmtpCommand.MAIL, params);
114 }
115 }
116
117
118
119
120 public static SmtpRequest rcpt(CharSequence recipient, CharSequence... rcptParameters) {
121 ObjectUtil.checkNotNull(recipient, "recipient");
122 if (rcptParameters == null || rcptParameters.length == 0) {
123 return new DefaultSmtpRequest(SmtpCommand.RCPT, "TO:<" + recipient + '>');
124 } else {
125 List<CharSequence> params = new ArrayList<CharSequence>(rcptParameters.length + 1);
126 params.add("TO:<" + recipient + '>');
127 Collections.addAll(params, rcptParameters);
128 return new DefaultSmtpRequest(SmtpCommand.RCPT, params);
129 }
130 }
131
132
133
134
135 public static SmtpRequest expn(CharSequence mailingList) {
136 return new DefaultSmtpRequest(SmtpCommand.EXPN, ObjectUtil.checkNotNull(mailingList, "mailingList"));
137 }
138
139
140
141
142 public static SmtpRequest vrfy(CharSequence user) {
143 return new DefaultSmtpRequest(SmtpCommand.VRFY, ObjectUtil.checkNotNull(user, "user"));
144 }
145
146 private SmtpRequests() { }
147 }