Yes, it seems that Message.getFrom()
can really return multiple addresses.
I had a look at the sources for Apache Geronimo's implementation of the JavaMail API, and it will return multiple addresses if there are multiple From:
headers, or multiple addresses inside one header.
As to whether this could happen:
As explained by Alex K.'s answer, the standard allows multiple "From" addresses if there is a single "Sender". I don't know whether anyone really sends mails with multiple "From" addresses, but it is standards-compliant.
Another situation which actually happens in practice:
Some spammers apparently send mail with multiple From:
headers. This is not standards-compliant, but apparently some mail servers still accept the mail. This is apparently done to get past mail filters that filter by the From:
address. The spammers include multiple addresses in the hope that a simple-minded filter will let the message pass if it finds one header with a "From"-address it likes.
So in summary: Yes, you should expect Message.getFrom()
to return multiple addresses (or none at all). However, you probably don't need to expend a lot of energy for handling that case. Maybe you can even get away with just logging it as an error - that depends on your application.