@@ -208,48 +208,21 @@ private MailRecipientCollection processRecipients(Message message, Message.Recip
208
208
semicolons. This is a hack to consider the case where the list of addresses is separated with semicolons which produces
209
209
an exception because the InternetAddress class used by jakarta mail to parse the addresses expects the list to be separated by commas
210
210
*/
211
- try {
212
- String [] addresses = message . getHeader ( rType . toString ());
213
- if ( addresses != null && addresses . length > 0 ) {
214
- for ( String address : addresses ) {
215
- String [] splitAddresses = address . split ( ";" );
216
- for ( String splitAddress : splitAddresses ) {
211
+ String [] addresses = message . getHeader ( rType . toString ());
212
+ if ( addresses != null && addresses . length > 0 ) {
213
+ for ( String address : addresses ) {
214
+ String [] splitAddresses = address . replace ( ";" , "," ). split ( "," );
215
+ for ( String splitAddress : splitAddresses ) {
216
+ try {
217
217
InternetAddress ia = new InternetAddress (splitAddress );
218
218
mailRecipient .addNew (ia .getPersonal (), ia .getAddress ());
219
+ } catch (AddressException ae ) {
220
+ logger .info ("Invalid email address" + splitAddress );
219
221
}
220
222
}
221
223
}
222
- return mailRecipient ;
223
-
224
- } catch (Exception originalException ) {
225
- try {
226
- String [] headers = message .getHeader (rType .toString ());
227
- if (headers != null ) {
228
- for (String header : headers ) {
229
- try {
230
- String normalized = header .replace (";" , "," ).trim ();
231
- int garbageIndex = normalized .indexOf ('(' );
232
- if (garbageIndex != -1 ) {
233
- normalized = normalized .substring (0 , garbageIndex ).trim ();
234
- }
235
- normalized = normalized .replaceAll (",\\ s*$" , "" );
236
-
237
- InternetAddress [] parsedAddresses = InternetAddress .parse (normalized , true );
238
- for (InternetAddress ia : parsedAddresses ) {
239
- mailRecipient .addNew (ia .getPersonal (), ia .getAddress ());
240
- }
241
- } catch (AddressException ae ) {
242
- logger .error ("Failed to parse email addresses from fallback header: " + header , ae );
243
- throw ae ;
244
- }
245
- }
246
- }
247
- return mailRecipient ;
248
- } catch (Exception fallbackException ) {
249
- logger .error ("Failed to extract email addresses." , fallbackException );
250
- throw new MessagingException ("Unable to extract recipient addresses from headers" , fallbackException );
251
- }
252
224
}
225
+ return mailRecipient ;
253
226
}
254
227
}
255
228
0 commit comments