1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -74,15 +74,9 @@ public SimpleMailMessage(SimpleMailMessage original) {
74
74
Assert .notNull (original , "'original' message argument must not be null" );
75
75
this .from = original .getFrom ();
76
76
this .replyTo = original .getReplyTo ();
77
- if (original .getTo () != null ) {
78
- this .to = copy (original .getTo ());
79
- }
80
- if (original .getCc () != null ) {
81
- this .cc = copy (original .getCc ());
82
- }
83
- if (original .getBcc () != null ) {
84
- this .bcc = copy (original .getBcc ());
85
- }
77
+ this .to = copyOrNull (original .getTo ());
78
+ this .cc = copyOrNull (original .getCc ());
79
+ this .bcc = copyOrNull (original .getBcc ());
86
80
this .sentDate = original .getSentDate ();
87
81
this .subject = original .getSubject ();
88
82
this .text = original .getText ();
@@ -182,21 +176,21 @@ public String getText() {
182
176
* @param target the {@code MailMessage} to copy to
183
177
*/
184
178
public void copyTo (MailMessage target ) {
185
- Assert .notNull (target , "'target' message argument must not be null" );
179
+ Assert .notNull (target , "'target' MailMessage must not be null" );
186
180
if (getFrom () != null ) {
187
181
target .setFrom (getFrom ());
188
182
}
189
183
if (getReplyTo () != null ) {
190
184
target .setReplyTo (getReplyTo ());
191
185
}
192
186
if (getTo () != null ) {
193
- target .setTo (getTo ());
187
+ target .setTo (copy ( getTo () ));
194
188
}
195
189
if (getCc () != null ) {
196
- target .setCc (getCc ());
190
+ target .setCc (copy ( getCc () ));
197
191
}
198
192
if (getBcc () != null ) {
199
- target .setBcc (getBcc ());
193
+ target .setBcc (copy ( getBcc () ));
200
194
}
201
195
if (getSentDate () != null ) {
202
196
target .setSentDate (getSentDate ());
@@ -210,20 +204,6 @@ public void copyTo(MailMessage target) {
210
204
}
211
205
212
206
213
- @ Override
214
- public String toString () {
215
- StringBuilder sb = new StringBuilder ("SimpleMailMessage: " );
216
- sb .append ("from=" ).append (this .from ).append ("; " );
217
- sb .append ("replyTo=" ).append (this .replyTo ).append ("; " );
218
- sb .append ("to=" ).append (StringUtils .arrayToCommaDelimitedString (this .to )).append ("; " );
219
- sb .append ("cc=" ).append (StringUtils .arrayToCommaDelimitedString (this .cc )).append ("; " );
220
- sb .append ("bcc=" ).append (StringUtils .arrayToCommaDelimitedString (this .bcc )).append ("; " );
221
- sb .append ("sentDate=" ).append (this .sentDate ).append ("; " );
222
- sb .append ("subject=" ).append (this .subject ).append ("; " );
223
- sb .append ("text=" ).append (this .text );
224
- return sb .toString ();
225
- }
226
-
227
207
@ Override
228
208
public boolean equals (Object other ) {
229
209
if (this == other ) {
@@ -235,33 +215,47 @@ public boolean equals(Object other) {
235
215
SimpleMailMessage otherMessage = (SimpleMailMessage ) other ;
236
216
return (ObjectUtils .nullSafeEquals (this .from , otherMessage .from ) &&
237
217
ObjectUtils .nullSafeEquals (this .replyTo , otherMessage .replyTo ) &&
238
- java . util . Arrays . equals (this .to , otherMessage .to ) &&
239
- java . util . Arrays . equals (this .cc , otherMessage .cc ) &&
240
- java . util . Arrays . equals (this .bcc , otherMessage .bcc ) &&
218
+ ObjectUtils . nullSafeEquals (this .to , otherMessage .to ) &&
219
+ ObjectUtils . nullSafeEquals (this .cc , otherMessage .cc ) &&
220
+ ObjectUtils . nullSafeEquals (this .bcc , otherMessage .bcc ) &&
241
221
ObjectUtils .nullSafeEquals (this .sentDate , otherMessage .sentDate ) &&
242
222
ObjectUtils .nullSafeEquals (this .subject , otherMessage .subject ) &&
243
223
ObjectUtils .nullSafeEquals (this .text , otherMessage .text ));
244
224
}
245
225
246
226
@ Override
247
227
public int hashCode () {
248
- int hashCode = (this .from == null ? 0 : this .from .hashCode ());
249
- hashCode = 29 * hashCode + (this .replyTo == null ? 0 : this .replyTo .hashCode ());
250
- for (int i = 0 ; this .to != null && i < this .to .length ; i ++) {
251
- hashCode = 29 * hashCode + (this .to == null ? 0 : this .to [i ].hashCode ());
252
- }
253
- for (int i = 0 ; this .cc != null && i < this .cc .length ; i ++) {
254
- hashCode = 29 * hashCode + (this .cc == null ? 0 : this .cc [i ].hashCode ());
255
- }
256
- for (int i = 0 ; this .bcc != null && i < this .bcc .length ; i ++) {
257
- hashCode = 29 * hashCode + (this .bcc == null ? 0 : this .bcc [i ].hashCode ());
258
- }
259
- hashCode = 29 * hashCode + (this .sentDate == null ? 0 : this .sentDate .hashCode ());
260
- hashCode = 29 * hashCode + (this .subject == null ? 0 : this .subject .hashCode ());
261
- hashCode = 29 * hashCode + (this .text == null ? 0 : this .text .hashCode ());
228
+ int hashCode = ObjectUtils .nullSafeHashCode (this .from );
229
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .replyTo );
230
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .to );
231
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .cc );
232
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .bcc );
233
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .sentDate );
234
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .subject );
262
235
return hashCode ;
263
236
}
264
237
238
+ @ Override
239
+ public String toString () {
240
+ StringBuilder sb = new StringBuilder ("SimpleMailMessage: " );
241
+ sb .append ("from=" ).append (this .from ).append ("; " );
242
+ sb .append ("replyTo=" ).append (this .replyTo ).append ("; " );
243
+ sb .append ("to=" ).append (StringUtils .arrayToCommaDelimitedString (this .to )).append ("; " );
244
+ sb .append ("cc=" ).append (StringUtils .arrayToCommaDelimitedString (this .cc )).append ("; " );
245
+ sb .append ("bcc=" ).append (StringUtils .arrayToCommaDelimitedString (this .bcc )).append ("; " );
246
+ sb .append ("sentDate=" ).append (this .sentDate ).append ("; " );
247
+ sb .append ("subject=" ).append (this .subject ).append ("; " );
248
+ sb .append ("text=" ).append (this .text );
249
+ return sb .toString ();
250
+ }
251
+
252
+
253
+ private static String [] copyOrNull (String [] state ) {
254
+ if (state == null ) {
255
+ return null ;
256
+ }
257
+ return copy (state );
258
+ }
265
259
266
260
private static String [] copy (String [] state ) {
267
261
String [] copy = new String [state .length ];
0 commit comments