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.
@@ -83,15 +83,9 @@ public SimpleMailMessage(SimpleMailMessage original) {
83
83
Assert .notNull (original , "'original' message argument must not be null" );
84
84
this .from = original .getFrom ();
85
85
this .replyTo = original .getReplyTo ();
86
- if (original .getTo () != null ) {
87
- this .to = copy (original .getTo ());
88
- }
89
- if (original .getCc () != null ) {
90
- this .cc = copy (original .getCc ());
91
- }
92
- if (original .getBcc () != null ) {
93
- this .bcc = copy (original .getBcc ());
94
- }
86
+ this .to = copyOrNull (original .getTo ());
87
+ this .cc = copyOrNull (original .getCc ());
88
+ this .bcc = copyOrNull (original .getBcc ());
95
89
this .sentDate = original .getSentDate ();
96
90
this .subject = original .getSubject ();
97
91
this .text = original .getText ();
@@ -199,21 +193,21 @@ public String getText() {
199
193
* @param target the {@code MailMessage} to copy to
200
194
*/
201
195
public void copyTo (MailMessage target ) {
202
- Assert .notNull (target , "'target' message argument must not be null" );
196
+ Assert .notNull (target , "'target' MailMessage must not be null" );
203
197
if (getFrom () != null ) {
204
198
target .setFrom (getFrom ());
205
199
}
206
200
if (getReplyTo () != null ) {
207
201
target .setReplyTo (getReplyTo ());
208
202
}
209
203
if (getTo () != null ) {
210
- target .setTo (getTo ());
204
+ target .setTo (copy ( getTo () ));
211
205
}
212
206
if (getCc () != null ) {
213
- target .setCc (getCc ());
207
+ target .setCc (copy ( getCc () ));
214
208
}
215
209
if (getBcc () != null ) {
216
- target .setBcc (getBcc ());
210
+ target .setBcc (copy ( getBcc () ));
217
211
}
218
212
if (getSentDate () != null ) {
219
213
target .setSentDate (getSentDate ());
@@ -227,20 +221,6 @@ public void copyTo(MailMessage target) {
227
221
}
228
222
229
223
230
- @ Override
231
- public String toString () {
232
- StringBuilder sb = new StringBuilder ("SimpleMailMessage: " );
233
- sb .append ("from=" ).append (this .from ).append ("; " );
234
- sb .append ("replyTo=" ).append (this .replyTo ).append ("; " );
235
- sb .append ("to=" ).append (StringUtils .arrayToCommaDelimitedString (this .to )).append ("; " );
236
- sb .append ("cc=" ).append (StringUtils .arrayToCommaDelimitedString (this .cc )).append ("; " );
237
- sb .append ("bcc=" ).append (StringUtils .arrayToCommaDelimitedString (this .bcc )).append ("; " );
238
- sb .append ("sentDate=" ).append (this .sentDate ).append ("; " );
239
- sb .append ("subject=" ).append (this .subject ).append ("; " );
240
- sb .append ("text=" ).append (this .text );
241
- return sb .toString ();
242
- }
243
-
244
224
@ Override
245
225
public boolean equals (Object other ) {
246
226
if (this == other ) {
@@ -252,33 +232,48 @@ public boolean equals(Object other) {
252
232
SimpleMailMessage otherMessage = (SimpleMailMessage ) other ;
253
233
return (ObjectUtils .nullSafeEquals (this .from , otherMessage .from ) &&
254
234
ObjectUtils .nullSafeEquals (this .replyTo , otherMessage .replyTo ) &&
255
- java . util . Arrays . equals (this .to , otherMessage .to ) &&
256
- java . util . Arrays . equals (this .cc , otherMessage .cc ) &&
257
- java . util . Arrays . equals (this .bcc , otherMessage .bcc ) &&
235
+ ObjectUtils . nullSafeEquals (this .to , otherMessage .to ) &&
236
+ ObjectUtils . nullSafeEquals (this .cc , otherMessage .cc ) &&
237
+ ObjectUtils . nullSafeEquals (this .bcc , otherMessage .bcc ) &&
258
238
ObjectUtils .nullSafeEquals (this .sentDate , otherMessage .sentDate ) &&
259
239
ObjectUtils .nullSafeEquals (this .subject , otherMessage .subject ) &&
260
240
ObjectUtils .nullSafeEquals (this .text , otherMessage .text ));
261
241
}
262
242
263
243
@ Override
264
244
public int hashCode () {
265
- int hashCode = (this .from == null ? 0 : this .from .hashCode ());
266
- hashCode = 29 * hashCode + (this .replyTo == null ? 0 : this .replyTo .hashCode ());
267
- for (int i = 0 ; this .to != null && i < this .to .length ; i ++) {
268
- hashCode = 29 * hashCode + (this .to == null ? 0 : this .to [i ].hashCode ());
269
- }
270
- for (int i = 0 ; this .cc != null && i < this .cc .length ; i ++) {
271
- hashCode = 29 * hashCode + (this .cc == null ? 0 : this .cc [i ].hashCode ());
272
- }
273
- for (int i = 0 ; this .bcc != null && i < this .bcc .length ; i ++) {
274
- hashCode = 29 * hashCode + (this .bcc == null ? 0 : this .bcc [i ].hashCode ());
275
- }
276
- hashCode = 29 * hashCode + (this .sentDate == null ? 0 : this .sentDate .hashCode ());
277
- hashCode = 29 * hashCode + (this .subject == null ? 0 : this .subject .hashCode ());
278
- hashCode = 29 * hashCode + (this .text == null ? 0 : this .text .hashCode ());
245
+ int hashCode = ObjectUtils .nullSafeHashCode (this .from );
246
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .replyTo );
247
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .to );
248
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .cc );
249
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .bcc );
250
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .sentDate );
251
+ hashCode = 29 * hashCode + ObjectUtils .nullSafeHashCode (this .subject );
279
252
return hashCode ;
280
253
}
281
254
255
+ @ Override
256
+ public String toString () {
257
+ StringBuilder sb = new StringBuilder ("SimpleMailMessage: " );
258
+ sb .append ("from=" ).append (this .from ).append ("; " );
259
+ sb .append ("replyTo=" ).append (this .replyTo ).append ("; " );
260
+ sb .append ("to=" ).append (StringUtils .arrayToCommaDelimitedString (this .to )).append ("; " );
261
+ sb .append ("cc=" ).append (StringUtils .arrayToCommaDelimitedString (this .cc )).append ("; " );
262
+ sb .append ("bcc=" ).append (StringUtils .arrayToCommaDelimitedString (this .bcc )).append ("; " );
263
+ sb .append ("sentDate=" ).append (this .sentDate ).append ("; " );
264
+ sb .append ("subject=" ).append (this .subject ).append ("; " );
265
+ sb .append ("text=" ).append (this .text );
266
+ return sb .toString ();
267
+ }
268
+
269
+
270
+ @ Nullable
271
+ private static String [] copyOrNull (@ Nullable String [] state ) {
272
+ if (state == null ) {
273
+ return null ;
274
+ }
275
+ return copy (state );
276
+ }
282
277
283
278
private static String [] copy (String [] state ) {
284
279
String [] copy = new String [state .length ];
0 commit comments