-
Notifications
You must be signed in to change notification settings - Fork 182
/
MovingMessage.java
129 lines (115 loc) · 4.57 KB
/
MovingMessage.java
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2014 Wael Chatila / Icegreen Technologies. All Rights Reserved.
* This software is released under the Apache license 2.0
* This file has been used and modified.
* Original file can be found on http://foedus.sourceforge.net
*/
package com.icegreen.greenmail.mail;
import jakarta.mail.internet.MimeMessage;
import java.util.LinkedList;
import java.util.List;
import com.icegreen.greenmail.smtp.auth.AuthenticationState;
import com.icegreen.greenmail.smtp.auth.LoginAuthenticationState;
import com.icegreen.greenmail.smtp.auth.PlainAuthenticationState;
/**
* Contains information for delivering a mime email.
*/
public class MovingMessage {
private AuthenticationState authenticationState;
private MailAddress returnPath;
private final List<MailAddress> toAddresses = new LinkedList<>();
private MimeMessage message;
/**
* Retrieves the state object with the data used for authentication. Currently
* {@link PlainAuthenticationState PLAIN} and {@link LoginAuthenticationState LOGIN}
* authentication is supported. You can use this, for example, to retrieve the username
* or password that was sent by the client.
*
* Note that this will return {@code null} when no authentication was performed or needed.
*
* @return The state used by the AUTH command, if any.
*/
public AuthenticationState getAuthenticationState() {
return authenticationState;
}
/**
* Retrieves the state object with the data used for authentication. Currently
* {@link PlainAuthenticationState PLAIN} and {@link LoginAuthenticationState LOGIN}
* authentication is supported. You can use this, for example, to retrieve the username
* or password that was sent by the client.
*
* Note that this will return {@code null} when no authentication was performed or needed.
*
* @return The state used by the AUTH command, if any.
*/
public void setAuthenticationState(AuthenticationState authenticationState) {
this.authenticationState = authenticationState;
}
/**
* Retrieves the addresses from which the email was sent. Note that these are
* the {@code RCPT TO} addresses from the SMTP envelope, not the {@code TO}
* addresses from the mail header.
* @return The address to which the mail is directed.
*/
public List<MailAddress> getToAddresses() {
return toAddresses;
}
/**
* Retrieves the contents of the mail message, including all mail headers and the body.
* @return The message that was sent.
*/
public MimeMessage getMessage() {
return message;
}
/**
* Retrieves the address from which the email was sent. Note that this is the
* {@code MAIL FROM} address from the SMTP envelope, not the {@code FROM}
* address(es) from the mail header.
* @return The address from which the email was sent.
*/
public MailAddress getReturnPath() {
return returnPath;
}
/**
* Sets or overwrites the address from which the email was sent. Note that this is
* the {@code MAIL FROM} address from the SMTP envelope, not the {@code FROM}
* address(es) from the mail header.
* @param fromAddress The address from which the email was sent.
*/
public void setReturnPath(MailAddress fromAddress) {
this.returnPath = fromAddress;
}
/**
* Adds an address from which the email was sent. Note that these are the {@code RCPT TO}
* addresses from the SMTP envelope, not the {@code TO} addresses from the mail header.
* @return The address to which the mail is directed.
*/
public void addRecipient(MailAddress s) {
toAddresses.add(s);
}
/**
* Removes an address from the list of addresses from which the email was sent. Note
* that these are the {@code RCPT TO} addresses from the SMTP envelope, not the {@code TO}
* addresses from the mail header.
* @return An address to remove form the addresses to which the mail is directed.
*/
public void removeRecipient(MailAddress s) {
toAddresses.remove(s);
}
/**
* Sets or overwrites the contents of the mail message, including all mail headers
* and the body.
* @param message The message that was sent.
*/
public void setMimeMessage(MimeMessage message) {
this.message = message;
}
@Override
public String toString() {
return "MovingMessage{" +
"toAddresses=" + toAddresses +
", returnPath=" + returnPath +
", message=" + message +
'}';
}
}