simple-java-mail icon indicating copy to clipboard operation
simple-java-mail copied to clipboard

outlookMsgToEmail duplicates recipients if same name used for To and Cc

Open atmcq opened this issue 1 year ago • 1 comments

Repeated in 8.8.3. outlookMsgToEmail() duplicates To and Cc addresses, seemingly depending on the "name" used for the recipient addresses matching.

Pass:

To Andrew McQuillen [email protected] Cc [email protected] [email protected]

[Recipient{name='Andrew McQuillen', address='[email protected]', type=To}, Recipient{name='[email protected]', address='[email protected]', type=Cc}]

Fail:

To Andrew McQuillen [email protected] Cc Andrew McQuillen [email protected]

[Recipient{name='Andrew McQuillen', address='[email protected]', type=To}, Recipient{name='Andrew McQuillen', address='[email protected]', type=To}, Recipient{name='Andrew McQuillen', address='[email protected]', type=Cc}, Recipient{name='Andrew McQuillen', address='[email protected]', type=Cc}]

Code to repeat using attached examples:

	@Test
	void givenMsgFile_avoidDuplicateCc() {
		try { 
			
			Email t_message = EmailConverter.outlookMsgToEmail(new File("TestingCC.msg"));
			assertTrue(countCcRecipients(t_message.getRecipients()) == 1);
			
			String t_eml = EmailConverter.emailToEML(t_message);
			
			Email t_message2 = EmailConverter.emlToEmail(new ByteArrayInputStream(t_eml.getBytes()));
			assertTrue(countCcRecipients(t_message2.getRecipients()) == 1);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	void givenMsgFileSameName_avoidDuplicateCc() {
		try { 
			
			Email t_message = EmailConverter.outlookMsgToEmail(new File("TestingCCSameName.msg"));
			assertTrue(countCcRecipients(t_message.getRecipients()) == 1);
			
			String t_eml = EmailConverter.emailToEML(t_message);
			
			Email t_message2 = EmailConverter.emlToEmail(new ByteArrayInputStream(t_eml.getBytes()));
			assertTrue(countCcRecipients(t_message2.getRecipients()) == 1);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
    public static int countCcRecipients(List<Recipient> recipients) {
        int ccCount = 0;
        for (Recipient recipient : recipients) {
            if ("Cc".equals(recipient.getType().toString())) {
                ccCount++;
            }
        }
        return ccCount;
    }

TestingMsg.zip

atmcq avatar Apr 16 '24 15:04 atmcq

Ok, I checked and this is actually a bug in outlook-message-parser. I added an issue there: https://github.com/bbottema/outlook-message-parser/issues/76.

bbottema avatar Apr 16 '24 18:04 bbottema