Susimail: Logging enhancements on file read failures

and UIDL mismatches
This commit is contained in:
zzz
2023-12-23 06:10:38 -05:00
parent 44dd19fe82
commit 2c03586e2d
2 changed files with 33 additions and 2 deletions
@@ -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());
}
}
}
@@ -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);