diff --git a/apps/susimail/src/src/i2p/susi/webmail/Mail.java b/apps/susimail/src/src/i2p/susi/webmail/Mail.java index 47e7c33e7..2c1f3404c 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/Mail.java +++ b/apps/susimail/src/src/i2p/susi/webmail/Mail.java @@ -49,6 +49,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import net.i2p.I2PAppContext; +import net.i2p.data.Base64; import net.i2p.data.DataHelper; import net.i2p.servlet.util.ServletUtil; import net.i2p.util.Log; @@ -127,6 +128,8 @@ class Mail { setHeader(rb, rb.getInputStream(), true); } catch (IOException ioe) { // TODO... + if (_log.shouldWarn()) + _log.warn("Header read error", ioe); } } @@ -524,6 +527,13 @@ class Mail { contentType = line.substring(13).trim(); } else if (hlc.startsWith("message-id:")) { messageID = line.substring(11).trim(); + } else if (hlc.startsWith("x-uidl:")) { + // shouldn't happen unless you imported or + // copied external emails to the cache + if (!uidl.equals(line.substring(7).trim()) && _log.shouldWarn()) + _log.warn("UIDL mismatch, may be unable to load body later. Original: " + uidl + + " b64: " + Base64.encode(uidl) + + " header: " + line.substring(7).trim()); } } } diff --git a/apps/susimail/src/src/i2p/susi/webmail/PersistentMailCache.java b/apps/susimail/src/src/i2p/susi/webmail/PersistentMailCache.java index 517ba9634..07c230099 100644 --- a/apps/susimail/src/src/i2p/susi/webmail/PersistentMailCache.java +++ b/apps/susimail/src/src/i2p/susi/webmail/PersistentMailCache.java @@ -205,22 +205,33 @@ class PersistentMailCache { } private boolean locked_getMail(Mail mail, boolean headerOnly) { + boolean found = false; File f = getFullFile(mail.uidl); if (f.exists()) { + found = true; Buffer rb = read(f); if (rb != null) { mail.setBody(rb); return true; + } else { + if (_log.shouldWarn()) + _log.warn("Unable to read file " + f); } } f = getHeaderFile(mail.uidl); if (f.exists()) { + found = true; Buffer rb = read(f); if (rb != null) { mail.setHeader(rb); return true; + } else { + if (_log.shouldWarn()) + _log.warn("Unable to read file " + f); } } + if (!found && _log.shouldWarn()) + _log.warn("Unable to find file " + f + " for mail " + Base64.encode(mail.uidl)); return false; } @@ -374,6 +385,8 @@ class PersistentMailCache { * @return null on failure */ private static Buffer read(File f) { + if (!f.canRead()) + return null; return new GzipFileBuffer(f); } @@ -396,11 +409,19 @@ class PersistentMailCache { } else { return null; } - if (uidl == null) + if (uidl == null) { + Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistentMailCache.class); + if (log.shouldWarn()) + log.warn("Unable to extract UIDL from file " + f); return null; + } Buffer rb = read(f); - if (rb == null) + if (rb == null) { + Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistentMailCache.class); + if (log.shouldWarn()) + log.warn("Unable to read file " + f); return null; + } Mail mail; if (isDrafts) mail = new Draft(uidl);