Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting problem: header X-MS-TNEF-Correlator is empty, so there is an exception #109

Closed
lacivert opened this issue Nov 1, 2017 · 2 comments

Comments

@lacivert
Copy link

lacivert commented Nov 1, 2017

I don't know if this is an issue of the project or the email server provider, but there is a problem on converting MimeMessage to Email.

I try to use https://ethereal.email to test emails. I use this code to fetch and get the emails via IMAP:

public static void main(String[] args) {
	Properties props = new Properties();
	props.setProperty("mail.store.protocol", "imaps");
	props.setProperty("mail.debug", "true");

	Folder inbox = null;
	Store store = null;
	try {
		// Connect to the server
		System.out.println("Connect to the server");
		Session session = Session.getInstance(props);
		
		String host = "imap.ethereal.email";
		String username = "qvvaodrw3lvfxboy@ethereal.email";
		String password = "4qvcgpNsPhwnQDNgzE";
		String provider = "imaps";
		
		store = session.getStore(provider);
		store.connect(host, username, password);
		
		// open the inbox folder
		System.out.println("open the inbox folder");
		inbox = store.getFolder("INBOX");
		UIDFolder uf = (UIDFolder) inbox;
		inbox.open(Folder.READ_ONLY);
		
		SearchTerm term = new SearchTerm() {

			private static final long serialVersionUID = 1L;

			public boolean match(Message message) {
		    		Calendar c = Calendar.getInstance();
		    		c.add(Calendar.DAY_OF_MONTH, -1);
		    		Date when = c.getTime();
	                        try {
					if (message.getReceivedDate().after(when)) {
					    return true;
					}
				} catch (MessagingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		        return false;
		    }
		};
		
		Message[] searchMessages = inbox.search(term);
		
		for (Message msg : searchMessages) {
			long uid = uf.getUID(msg);
			System.out.println("uid: " + uid);
		        MimeMessage mimeMsg = (MimeMessage) msg;
			Email email = EmailConverter.mimeMessageToEmail(mimeMsg);
			String html = email.getTextHTML();
			String text = html.substring(0, html.indexOf(DELIMITER));
			System.out.println(text);
		}
	}
	catch (Exception ex) {
		System.out.println("Thread has a problem...");
		ex.printStackTrace();
	}

	finally {
		// close the inbox folder but do not
		// remove the messages from the server
		try {
			inbox.close(false);
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		try {
			store.close();
		} catch (MessagingException e) {
			e.printStackTrace();
		}
		System.out.println("Thread is closing...");
	}
}

I got this exception:

java.lang.IllegalArgumentException: value is required
	at org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument(Preconditions.java:15)
	at org.simplejavamail.email.Email.addHeader(Email.java:519)
	at org.simplejavamail.converter.EmailConverter.fillEmailFromMimeMessage(EmailConverter.java:245)
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmail(EmailConverter.java:56)

I debugged the code and I got that the key of the header is: X-MS-TNEF-Correlator
The value is an empty string.

At this point, only because of a missing header value, I cannot get the email message converted. Isn't it some weird? I can get the other parts of the email by using all the other methods. But here, I think simple-mail should let me have the rest of the email converted even if there are some missing header parts (which I don't even know if we need or not).

@bbottema
Copy link
Owner

bbottema commented Nov 1, 2017

You're right, it should be able to convert the email without issue. I'll look into it.

@bbottema
Copy link
Owner

Released as 5.0.0.rc1-SNAPSHOT. Add OSS' snapshots repo to find it in Maven.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants