mail-notify: fix NPE when sender is only mail address without name

This commit is contained in:
Alexander Gehrke 2023-03-02 13:20:09 +01:00
parent 5b0216753e
commit 7b7c3dd36f

View file

@ -12,13 +12,13 @@ val icon = "/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png"
val cacheFile = envPath("XDG_CACHE_HOME", os.home/".cache") / "seen-mails"
val maildir = envPath("MAILDIR", os.home/"Mail")
case class MailInfo(from: String, subject: String, mailbox: String)
object MailInfo {
def fromPath(p: os.Path, maildir: os.Path) = {
val msg = readMessage(p)
val address = msg.getFrom.head.asInstanceOf[InternetAddress]
MailInfo(
msg.getFrom.head.asInstanceOf[InternetAddress].getPersonal.replace("&", "&"),
Option(address.getPersonal).map(_.replace("&", "&")).getOrElse(address.getAddress),
msg.getSubject.replace("&", "&"),
(p/up/up relativeTo maildir).toString
)