SusiMail: Move logging to router logs (ticket #2191)

This commit is contained in:
zzz
2018-04-16 11:06:18 +00:00
parent 8c0e82d4f3
commit b9bc254fd3
15 changed files with 249 additions and 264 deletions

View File

@@ -1,62 +0,0 @@
/*
* Created on Nov 4, 2004
*
* This file is part of susimail project, see http://susi.i2p/
*
* Copyright (C) 2004-2005 <susi23@mail.i2p>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Revision: 1.2 $
*/
package i2p.susi.debug;
import net.i2p.I2PAppContext;
/**
* @author susi23
*/
public class Debug {
public static final int ERROR = 1;
public static final int DEBUG = 2;
private static int level = ERROR;
public static void setLevel( int newLevel )
{
level = newLevel;
}
/** @since 0.9.13 */
public static int getLevel() {
return level;
}
public static void debug( int msgLevel, String msg ) {
debug(msgLevel, msg, null);
}
/** @since 0.9.34 */
public static void debug(int msgLevel, String msg, Throwable t)
{
if( msgLevel <= level ) {
System.err.println("SusiMail: " + msg);
if (t != null)
t.printStackTrace();
}
if (msgLevel <= ERROR)
I2PAppContext.getGlobalContext().logManager().getLog(Debug.class).error(msg, t);
}
}

View File

@@ -23,8 +23,6 @@
*/
package i2p.susi.util;
import i2p.susi.debug.Debug;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -34,6 +32,7 @@ import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;
import net.i2p.util.OrderedProperties;
/**
@@ -92,14 +91,15 @@ public class Config {
*/
public synchronized static void reloadConfiguration()
{
// DEBUG level logging won't work here since we haven't loaded the config yet...
I2PAppContext ctx = I2PAppContext.getGlobalContext();
properties = new Properties();
InputStream iv = null;
try {
iv = Config.class.getResourceAsStream("/susimail.properties");
properties.load(iv);
} catch (IOException e) {
Debug.debug(Debug.ERROR, "Could not open WEB-INF/classes/susimail.properties (possibly in jar), reason: " + e);
Log log = ctx.logManager().getLog(Config.class);
log.error("Could not open WEB-INF/classes/susimail.properties (possibly in jar)", e);
} finally {
if(iv != null) try { iv.close(); } catch(IOException ioe) {}
}
@@ -110,7 +110,8 @@ public class Config {
DataHelper.loadProps(config, cfg);
}
} catch (IOException e) {
Debug.debug(Debug.ERROR, "Could not open susimail.config, reason: " + e);
Log log = ctx.logManager().getLog(Config.class);
log.error("Could not open susimail.config", e);
}
}

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail;
import i2p.susi.debug.Debug;
import i2p.susi.util.Buffer;
import i2p.susi.util.Config;
import i2p.susi.util.CountingInputStream;
@@ -51,6 +50,7 @@ import java.util.regex.Pattern;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.servlet.util.ServletUtil;
import net.i2p.util.Log;
import net.i2p.util.RFC822Date;
import net.i2p.util.SystemVersion;
@@ -96,6 +96,7 @@ class Mail {
public String error;
public boolean markForDeletion;
private final Log _log;
public Mail(String uidl) {
this.uidl = uidl;
@@ -108,6 +109,7 @@ class Mail {
shortSubject = "";
quotedDate = unknown;
error = "";
_log = I2PAppContext.getGlobalContext().logManager().getLog(Mail.class);
}
/**
@@ -186,9 +188,9 @@ class Mail {
size = rb.getLength();
success = true;
} catch (IOException de) {
Debug.debug(Debug.ERROR, "Decode error", de);
_log.error("Decode error", de);
} catch (RuntimeException e) {
Debug.debug(Debug.ERROR, "Parse error", e);
_log.error("Parse error", e);
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
rb.readComplete(success);
@@ -410,7 +412,7 @@ class Mail {
MemoryBuffer decoded = new MemoryBuffer(4096);
hl.decode(eofin, decoded);
if (!eofin.wasFound())
Debug.debug(Debug.DEBUG, "EOF hit before \\r\\n\\r\\n in Mail");
if (_log.shouldDebug()) _log.debug("EOF hit before \\r\\n\\r\\n in Mail");
// Fixme UTF-8 to bytes to UTF-8
headerLines = DataHelper.split(new String(decoded.getContent(), decoded.getOffset(), decoded.getLength()), "\r\n");
for (int j = 0; j < headerLines.length; j++) {
@@ -501,7 +503,7 @@ class Mail {
}
catch( Exception e ) {
error += "Error parsing mail header: " + e.getClass().getName() + '\n';
Debug.debug(Debug.ERROR, "Parse error", e);
_log.error("Parse error", e);
}
}
}

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail;
import i2p.susi.debug.Debug;
import i2p.susi.util.Config;
import i2p.susi.util.Buffer;
import i2p.susi.util.FileBuffer;
@@ -48,6 +47,7 @@ import java.util.Set;
import net.i2p.I2PAppContext;
import net.i2p.util.FileUtil;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
/**
* There's one of these for each Folder.
@@ -70,6 +70,7 @@ class MailCache {
private NewMailListener _loadInProgress;
private boolean _isLoaded;
private final boolean _isDrafts;
private final Log _log;
/** Includes header, headers are generally 1KB to 1.5 KB,
* and bodies will compress well.
@@ -84,6 +85,7 @@ class MailCache {
*/
MailCache(I2PAppContext ctx, POP3MailBox mailbox, String folderName,
String host, int port, String user, String pass) throws IOException {
_log = ctx.logManager().getLog(MailCache.class);
this.mailbox = mailbox;
mails = new Hashtable<String, Mail>();
disk = new PersistentMailCache(ctx, host, port, user, pass, folderName);
@@ -242,7 +244,7 @@ class MailCache {
public synchronized boolean loadFromDisk(NewMailListener nml) {
if (_isLoaded || _loadInProgress != null)
return false;
Debug.debug(Debug.DEBUG, "Loading folder " + folderName);
if (_log.shouldDebug()) _log.debug("Loading folder " + folderName);
Thread t = new I2PAppThread(new LoadMailRunner(nml), "Email loader");
_loadInProgress = nml;
try {
@@ -268,7 +270,7 @@ class MailCache {
blockingLoadFromDisk();
if(!mails.isEmpty())
result = true;
Debug.debug(Debug.DEBUG, "Folder loaded: " + folderName);
if (_log.shouldDebug()) _log.debug("Folder loaded: " + folderName);
} finally {
synchronized(MailCache.this) {
if (_loadInProgress == _nml)
@@ -401,7 +403,7 @@ class MailCache {
if (mode == FetchMode.CACHE_ONLY)
throw new IllegalArgumentException();
if (mailbox == null) {
Debug.debug(Debug.DEBUG, "getMail() mode " + mode + " called on wrong folder " + getFolderName(), new Exception());
if (_log.shouldDebug()) _log.debug("getMail() mode " + mode + " called on wrong folder " + getFolderName(), new Exception());
return false;
}
boolean hOnly = mode == FetchMode.HEADER;
@@ -439,7 +441,7 @@ class MailCache {
if(!mail.hasHeader()) {
if (disk != null) {
if (disk.getMail(mail, true)) {
Debug.debug(Debug.DEBUG, "Loaded header from disk cache: " + uidl);
if (_log.shouldDebug()) _log.debug("Loaded header from disk cache: " + uidl);
// note that disk loaded the full body if it had it
if (mail.hasBody() &&
!Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) {
@@ -462,7 +464,7 @@ class MailCache {
if(!mail.hasBody()) {
if (disk != null) {
if (disk.getMail(mail, false)) {
Debug.debug(Debug.DEBUG, "Loaded body from disk cache: " + uidl);
if (_log.shouldDebug()) _log.debug("Loaded body from disk cache: " + uidl);
// note that disk loaded the full body if it had it
if (!Boolean.parseBoolean(Config.getProperty(WebMail.CONFIG_LEAVE_ON_SERVER))) {
// we already have it, send delete

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail;
import i2p.susi.debug.Debug;
import i2p.susi.util.Buffer;
import i2p.susi.util.CountingOutputStream;
import i2p.susi.util.DummyOutputStream;
@@ -46,7 +45,9 @@ import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;
/**
* @author susi23
@@ -68,6 +69,7 @@ class MailPart {
public final List<MailPart> parts;
public final boolean multipart, message;
public final Buffer buffer;
private final Log _log;
/**
* the decoded length if known, else -1
@@ -92,6 +94,7 @@ class MailPart {
*/
public MailPart(String uidl, AtomicInteger id, Buffer readBuffer, InputStream in, ReadCounter counter, String[] hdrlines) throws IOException
{
_log = I2PAppContext.getGlobalContext().logManager().getLog(MailPart.class);
this.uidl = uidl;
intID = id.getAndIncrement();
buffer = readBuffer;
@@ -113,7 +116,7 @@ class MailPart {
MemoryBuffer decodedHeaders = new MemoryBuffer(4096);
EncodingFactory.getEncoding("HEADERLINE").decode(eofin, decodedHeaders);
if (!eofin.wasFound())
Debug.debug(Debug.DEBUG, "EOF hit before \\r\\n\\r\\n in MailPart");
if (_log.shouldDebug()) _log.debug("EOF hit before \\r\\n\\r\\n in MailPart");
// Fixme UTF-8 to bytes to UTF-8
headerLines = DataHelper.split(new String(decodedHeaders.getContent(), decodedHeaders.getOffset(), decodedHeaders.getLength()), "\r\n");
}
@@ -193,7 +196,7 @@ class MailPart {
// swallow the \n
int c = in.read();
if (c != '\n')
Debug.debug(Debug.DEBUG, "wasn't a \\n, it was " + c);
if (_log.shouldDebug()) _log.debug("wasn't a \\n, it was " + c);
beginBody = (int) counter.getRead();
}
@@ -211,10 +214,10 @@ class MailPart {
OutputStream dummy = new DummyOutputStream();
DataHelper.copy(eofin, dummy);
if (!eofin.wasFound())
Debug.debug(Debug.DEBUG, "EOF hit before first boundary " + boundary + " UIDL: " + uidl);
if (_log.shouldDebug()) _log.debug("EOF hit before first boundary " + boundary + " UIDL: " + uidl);
if (readBoundaryTrailer(in)) {
if (!eofin.wasFound())
Debug.debug(Debug.DEBUG, "EOF hit before first part body " + boundary + " UIDL: " + uidl);
if (_log.shouldDebug()) _log.debug("EOF hit before first part body " + boundary + " UIDL: " + uidl);
tmpEnd = (int) eofin.getRead();
break;
}
@@ -229,7 +232,7 @@ class MailPart {
// if MailPart contains a MailPart, we may not have drained to the end
DataHelper.copy(eofin, DUMMY_OUTPUT);
if (!eofin.wasFound())
Debug.debug(Debug.DEBUG, "EOF hit before end of body " + i + " boundary: " + boundary + " UIDL: " + uidl);
if (_log.shouldDebug()) _log.debug("EOF hit before end of body " + i + " boundary: " + boundary + " UIDL: " + uidl);
}
if (readBoundaryTrailer(in))
break;
@@ -251,7 +254,7 @@ class MailPart {
decodedLength = end - beginBody;
}
//if (Debug.getLevel() >= Debug.DEBUG)
// Debug.debug(Debug.DEBUG, "New " + this);
// if (_log.shouldDebug()) _log.debug("New " + this);
}
/**
@@ -269,13 +272,13 @@ class MailPart {
*
* @return true if end of input
*/
private static boolean readBoundaryTrailer(InputStream in) throws IOException {
private boolean readBoundaryTrailer(InputStream in) throws IOException {
int c = in.read();
if (c == '-') {
// end of parts with this boundary
c = in.read();
if (c != '-') {
Debug.debug(Debug.DEBUG, "Unexpected char after boundary-: " + c);
if (_log.shouldDebug()) _log.debug("Unexpected char after boundary-: " + c);
return true;
}
c = in.read();
@@ -283,19 +286,19 @@ class MailPart {
return true;
}
if (c != '\r') {
Debug.debug(Debug.DEBUG, "Unexpected char after boundary--: " + c);
if (_log.shouldDebug()) _log.debug("Unexpected char after boundary--: " + c);
return true;
}
c = in.read();
if (c != '\n')
Debug.debug(Debug.DEBUG, "Unexpected char after boundary--\\r: " + c);
if (_log.shouldDebug()) _log.debug("Unexpected char after boundary--\\r: " + c);
return true;
} else if (c == '\r') {
c = in.read();
if (c != '\n')
Debug.debug(Debug.DEBUG, "Unexpected char after boundary\\r: " + c);
if (_log.shouldDebug()) _log.debug("Unexpected char after boundary\\r: " + c);
} else {
Debug.debug(Debug.DEBUG, "Unexpected char after boundary: " + c);
if (_log.shouldDebug()) _log.debug("Unexpected char after boundary: " + c);
}
return c == -1;
}
@@ -310,7 +313,7 @@ class MailPart {
String encg = encoding;
if (encg == null) {
//throw new DecodingException("No encoding specified");
Debug.debug(Debug.DEBUG, "Warning: no transfer encoding found, fallback to 7bit.");
if (_log.shouldDebug()) _log.debug("Warning: no transfer encoding found, fallback to 7bit.");
encg = "7bit";
}
Encoding enc = EncodingFactory.getEncoding(encg);
@@ -332,13 +335,13 @@ class MailPart {
//dout.getOutputStream().flush();
} catch (IOException ioe) {
if (lin != null)
Debug.debug(Debug.DEBUG, "Decode IOE at in position " + lin.getRead()
if (_log.shouldDebug()) _log.debug("Decode IOE at in position " + lin.getRead()
+ " offset " + offset, ioe);
else if (cos != null)
Debug.debug(Debug.DEBUG, "Decode IOE at out position " + cos.getWritten()
if (_log.shouldDebug()) _log.debug("Decode IOE at out position " + cos.getWritten()
+ " offset " + offset, ioe);
else
Debug.debug(Debug.DEBUG, "Decode IOE", ioe);
if (_log.shouldDebug()) _log.debug("Decode IOE", ioe);
throw ioe;
} finally {
if (lin != null) try { lin.close(); } catch (IOException ioe) {};
@@ -365,7 +368,7 @@ class MailPart {
lin = getRawInputStream(0);
DataHelper.copy(lin, out);
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Decode IOE", ioe);
if (_log.shouldDebug()) _log.debug("Decode IOE", ioe);
throw ioe;
} finally {
if (lin != null) try { lin.close(); } catch (IOException ioe) {};

View File

@@ -1,6 +1,5 @@
package i2p.susi.webmail;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.Messages;
import i2p.susi.util.Buffer;
import i2p.susi.util.FileBuffer;
@@ -33,6 +32,7 @@ import net.i2p.data.Base64;
import net.i2p.data.DataHelper;
import net.i2p.util.FileSuffixFilter;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
import net.i2p.util.PasswordManager;
import net.i2p.util.SecureDirectory;
import net.i2p.util.SecureFile;
@@ -73,6 +73,7 @@ class PersistentMailCache {
// non-null only for Drafts
private final File _attachmentDir;
private final I2PAppContext _context;
private final Log _log;
private final boolean _isDrafts;
private static final String DIR_SUSI = "susimail";
@@ -96,6 +97,7 @@ class PersistentMailCache {
*/
public PersistentMailCache(I2PAppContext ctx, String host, int port, String user, String pass, String folder) throws IOException {
_context = ctx;
_log = ctx.logManager().getLog(PersistentMailCache.class);
_isDrafts = folder.equals(WebMail.DIR_DRAFTS);
_lock = getLock(host, port, user, pass);
synchronized(_lock) {
@@ -163,7 +165,7 @@ class PersistentMailCache {
}
}
long end = _context.clock().now();
Debug.debug(Debug.DEBUG, "Loaded " + sz + " emails with " + tcnt + " threads in " + DataHelper.formatDuration(end - begin));
if (_log.shouldDebug()) _log.debug("Loaded " + sz + " emails with " + tcnt + " threads in " + DataHelper.formatDuration(end - begin));
return rv;
}
@@ -347,7 +349,7 @@ class PersistentMailCache {
*
* @return success
*/
private static boolean write(Buffer rb, File f) {
private boolean write(Buffer rb, File f) {
InputStream in = null;
OutputStream out = null;
try {
@@ -357,7 +359,7 @@ class PersistentMailCache {
DataHelper.copy(in, out);
return true;
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Error writing: " + f + ": " + ioe);
_log.error("Error writing: " + f + ": " + ioe);
return false;
} finally {
if (in != null)
@@ -437,7 +439,7 @@ class PersistentMailCache {
}
}
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Import failed " + f, ioe);
_log.error("Import failed " + f, ioe);
continue;
} finally {
if (in != null)
@@ -447,7 +449,7 @@ class PersistentMailCache {
uidl = Long.toString(_context.random().nextLong());
File to = getFullFile(uidl);
if (to.exists()) {
Debug.debug(Debug.DEBUG, "Already have " + f + " as UIDL " + uidl);
if (_log.shouldDebug()) _log.debug("Already have " + f + " as UIDL " + uidl);
f.delete();
continue;
}
@@ -460,7 +462,7 @@ class PersistentMailCache {
out = new FixCRLFOutputStream(gb.getOutputStream());
DataHelper.copy(in, out);
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Import failed " + f, ioe);
_log.error("Import failed " + f, ioe);
continue;
} finally {
if (in != null)
@@ -469,7 +471,7 @@ class PersistentMailCache {
try { out.close(); } catch (IOException ioe) {}
}
f.delete();
Debug.debug(Debug.DEBUG, "Imported " + f + " as UIDL " + uidl);
if (_log.shouldDebug()) _log.debug("Imported " + f + " as UIDL " + uidl);
}
}
}

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail;
import i2p.susi.debug.Debug;
import i2p.susi.util.Buffer;
import i2p.susi.util.Config;
import i2p.susi.util.DecodingOutputStream;
@@ -89,6 +88,7 @@ import net.i2p.servlet.RequestWrapper;
import net.i2p.servlet.util.ServletUtil;
import net.i2p.servlet.util.WriterOutputStream;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
import net.i2p.util.RFC822Date;
import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.Translate;
@@ -98,10 +98,8 @@ import net.i2p.util.Translate;
*/
public class WebMail extends HttpServlet
{
/*
* set to true, if its a release build
*/
private static final boolean RELEASE;
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(WebMail.class);
/*
* increase version number for every release
*/
@@ -268,8 +266,6 @@ public class WebMail extends HttpServlet
static {
Config.setPrefix( "susimail" );
RELEASE = !Boolean.parseBoolean(Config.getProperty(CONFIG_DEBUG));
Debug.setLevel( RELEASE ? Debug.ERROR : Debug.DEBUG );
}
@@ -299,12 +295,19 @@ public class WebMail extends HttpServlet
boolean bccToSelf;
private final List<String> nonces;
private static final int MAX_NONCES = 15;
public final Log log;
SessionObject()
SessionObject(Log log)
{
bccToSelf = Boolean.parseBoolean(Config.getProperty( CONFIG_BCC_TO_SELF, "true" ));
nonces = new ArrayList<String>(MAX_NONCES + 1);
caches = new HashMap<String, MailCache>(8);
this.log = log;
String dbg = Config.getProperty(CONFIG_DEBUG);
if (dbg != null) {
boolean release = !Boolean.parseBoolean(dbg);
log.setMinimumPriority(release ? Log.ERROR : Log.DEBUG);
}
}
/** @since 0.9.13 */
@@ -315,7 +318,7 @@ public class WebMail extends HttpServlet
* @since 0.9.13
*/
public void valueUnbound(HttpSessionBindingEvent event) {
Debug.debug(Debug.DEBUG, "Session unbound: " + event.getSession().getId());
if (log.shouldDebug()) log.debug("Session unbound: " + event.getSession().getId());
POP3MailBox mbox = mailbox;
if (mbox != null) {
mbox.destroy();
@@ -780,6 +783,7 @@ public class WebMail extends HttpServlet
String host, int pop3PortNo, String user, String pass) {
POP3MailBox mailbox = new POP3MailBox(host, pop3PortNo, user, pass);
I2PAppContext ctx = I2PAppContext.getGlobalContext();
Log log = sessionObject.log;
MailCache mc;
try {
mc = new MailCache(ctx, mailbox, DIR_FOLDER,
@@ -798,7 +802,7 @@ public class WebMail extends HttpServlet
host, pop3PortNo, user, pass);
sessionObject.caches.put(DIR_SPAM, mc2);
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Error creating disk cache", ioe);
log.error("Error creating disk cache", ioe);
sessionObject.error += ioe.toString() + '\n';
return State.AUTH;
}
@@ -820,7 +824,7 @@ public class WebMail extends HttpServlet
// thread 2: mailbox.connectToServer()
if (offline) {
Debug.debug(Debug.DEBUG, "OFFLINE MODE");
if (log.shouldDebug()) log.debug("OFFLINE MODE");
} else {
sessionObject.isFetching = true;
if (!mailbox.connectToServer(new ConnectWaiter(sessionObject))) {
@@ -834,7 +838,7 @@ public class WebMail extends HttpServlet
try {
sessionObject.wait(5000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for load", ie);
if (log.shouldDebug()) log.debug("Interrupted waiting for load", ie);
}
}
state = mc.isLoading() ? State.LOADING : State.LIST;
@@ -890,8 +894,9 @@ public class WebMail extends HttpServlet
MailCache mc = null;
Folder<String> f = null;
boolean found = false;
Log log = _so.log;
if (connected) {
Debug.debug(Debug.DEBUG, "CONNECTED, YAY");
if (log.shouldDebug()) log.debug("CONNECTED, YAY");
// we do this whether new mail was found or not,
// because we may already have UIDLs in the MailCache to fetch
synchronized(_so) {
@@ -900,19 +905,19 @@ public class WebMail extends HttpServlet
try {
_so.wait(5000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for load", ie);
if (log.shouldDebug()) log.debug("Interrupted waiting for load", ie);
return;
}
}
}
Debug.debug(Debug.DEBUG, "Done waiting for folder load");
if (log.shouldDebug()) log.debug("Done waiting for folder load");
// fetch the mail outside the lock
// TODO, would be better to add each email as we get it
if (mc != null) {
found = mc.getMail(MailCache.FetchMode.HEADER);
}
} else {
Debug.debug(Debug.DEBUG, "NOT CONNECTED, BOO");
if (log.shouldDebug()) log.debug("NOT CONNECTED, BOO");
}
synchronized(_so) {
if (!connected) {
@@ -922,7 +927,7 @@ public class WebMail extends HttpServlet
else
_so.connectError = _t("Error connecting to server");
} else if (!found) {
Debug.debug(Debug.DEBUG, "No new emails");
if (log.shouldDebug()) log.debug("No new emails");
_so.newMails = 0;
_so.connectError = null;
} else if (mc != null && f != null) {
@@ -932,9 +937,9 @@ public class WebMail extends HttpServlet
_so.pageChanged = true;
_so.newMails = added;
_so.connectError = null;
Debug.debug(Debug.DEBUG, "Added " + added + " new emails");
if (log.shouldDebug()) log.debug("Added " + added + " new emails");
} else {
Debug.debug(Debug.DEBUG, "MailCache/folder vanished?");
if (log.shouldDebug()) log.debug("MailCache/folder vanished?");
}
_mb.setNewMailListener(_so);
_so.isFetching = false;
@@ -952,8 +957,9 @@ public class WebMail extends HttpServlet
*/
private static State processLogout(SessionObject sessionObject, RequestWrapper request, boolean isPOST, State state)
{
Log log = sessionObject.log;
if( buttonPressed( request, LOGOUT ) && isPOST) {
Debug.debug(Debug.DEBUG, "LOGOUT, REMOVING SESSION");
if (log.shouldDebug()) log.debug("LOGOUT, REMOVING SESSION");
HttpSession session = request.getSession();
session.removeAttribute( "sessionObject" );
session.invalidate();
@@ -969,7 +975,7 @@ public class WebMail extends HttpServlet
!buttonPressed(request, SAVE)) {
// AUTH will be passed in if mailbox is null
// Check previous state
Debug.debug(Debug.DEBUG, "Lost conn, prev. state was " + request.getParameter(DEBUG_STATE));
if (log.shouldDebug()) log.debug("Lost conn, prev. state was " + request.getParameter(DEBUG_STATE));
sessionObject.error += _t("Internal error, lost connection.") + '\n' +
_t("User logged out.") + '\n';
}
@@ -1002,6 +1008,7 @@ public class WebMail extends HttpServlet
if (mc.isLoading())
return State.LOADING;
}
Log log = sessionObject.log;
/*
* compose dialog
@@ -1015,7 +1022,7 @@ public class WebMail extends HttpServlet
String uidl = Base64.decodeToString(request.getParameter(NEW_UIDL));
if (uidl == null)
uidl = I2PAppContext.getGlobalContext().random().nextLong() + "drft";
Debug.debug(Debug.DEBUG, "Save as draft: " + uidl);
if (log.shouldDebug()) log.debug("Save as draft: " + uidl);
MailCache toMC = sessionObject.caches.get(DIR_DRAFTS);
Writer wout = null;
boolean ok = false;
@@ -1030,11 +1037,11 @@ public class WebMail extends HttpServlet
buffer = toMC.getFullWriteBuffer(uidl);
wout = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), "ISO-8859-1"));
SMTPClient.writeMail(wout, draft, null, null);
Debug.debug(Debug.DEBUG, "Saved as draft: " + uidl);
if (log.shouldDebug()) log.debug("Saved as draft: " + uidl);
ok = true;
} catch (IOException ioe) {
sessionObject.error += _t("Unable to save mail.") + ' ' + ioe.getMessage() + '\n';
Debug.debug(Debug.DEBUG, "Unable to save as draft: " + uidl, ioe);
if (log.shouldDebug()) log.debug("Unable to save as draft: " + uidl, ioe);
} finally {
if (wout != null) try { wout.close(); } catch (IOException ioe) {}
if (buffer != null)
@@ -1052,13 +1059,13 @@ public class WebMail extends HttpServlet
} else if (ok && buttonPressed(request, SEND)) {
Draft mail = (Draft) toMC.getMail(uidl, MailCache.FetchMode.CACHE_ONLY);
if (mail != null) {
Debug.debug(Debug.DEBUG, "Send mail: " + uidl);
if (log.shouldDebug()) log.debug("Send mail: " + uidl);
ok = sendMail(sessionObject, mail);
} else {
// couldn't read it back in?
ok = false;
sessionObject.error += _t("Unable to save mail.") + '\n';
Debug.debug(Debug.DEBUG, "Draft readback fail: " + uidl);
if (log.shouldDebug()) log.debug("Draft readback fail: " + uidl);
}
}
if (ok) {
@@ -1070,7 +1077,7 @@ public class WebMail extends HttpServlet
} else {
state = State.NEW;
}
Debug.debug(Debug.DEBUG, "State after save as draft: " + state);
if (log.shouldDebug()) log.debug("State after save as draft: " + state);
} else if (buttonPressed(request, CANCEL)) {
// If we have a reference UIDL, go back to that
if (request.getParameter(B64UIDL) != null)
@@ -1360,11 +1367,12 @@ public class WebMail extends HttpServlet
// shouldn't happen, button disabled
return state;
}
Log log = sessionObject.log;
sessionObject.isFetching = true;
ConnectWaiter cw = new ConnectWaiter(sessionObject);
if (mailbox.connectToServer(cw)) {
// Start a thread to wait for results
Debug.debug(Debug.DEBUG, "Already connected, running CW");
if (log.shouldDebug()) log.debug("Already connected, running CW");
Thread t = new I2PAppThread(cw, "Email fetcher");
t.start();
} else {
@@ -1375,7 +1383,7 @@ public class WebMail extends HttpServlet
try {
sessionObject.wait(3000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for connect", ie);
if (log.shouldDebug()) log.debug("Interrupted waiting for connect", ie);
}
}
return state;
@@ -1771,8 +1779,12 @@ public class WebMail extends HttpServlet
} catch( NumberFormatException nfe ) {}
}
Config.saveConfiguration(props);
boolean release = !Boolean.parseBoolean(props.getProperty(CONFIG_DEBUG));
Debug.setLevel( release ? Debug.ERROR : Debug.DEBUG );
String dbg = props.getProperty(CONFIG_DEBUG);
if (dbg != null) {
boolean release = !Boolean.parseBoolean(dbg);
Log log = sessionObject.log;
log.setMinimumPriority(release ? Log.ERROR : Log.DEBUG);
}
state = folder != null ? State.LIST : State.AUTH;
sessionObject.info = _t("Configuration saved");
} catch (IOException ioe) {
@@ -1816,11 +1828,11 @@ public class WebMail extends HttpServlet
SessionObject sessionObject = (SessionObject)httpSession.getAttribute( "sessionObject" );
if( sessionObject == null ) {
sessionObject = new SessionObject();
sessionObject = new SessionObject(_log);
httpSession.setAttribute( "sessionObject", sessionObject );
Debug.debug(Debug.DEBUG, "NEW session " + httpSession.getId());
if (_log.shouldDebug()) _log.debug("NEW session " + httpSession.getId());
} else {
Debug.debug(Debug.DEBUG, "Existing session " + httpSession.getId() +
if (_log.shouldDebug()) _log.debug("Existing session " + httpSession.getId() +
" created " + new Date(httpSession.getCreationTime()));
}
return sessionObject;
@@ -1895,7 +1907,8 @@ public class WebMail extends HttpServlet
try {
sessionObject.wait(5000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for load", ie);
Log log = sessionObject.log;
if (log.shouldDebug()) log.debug("Interrupted waiting for load", ie);
}
}
}
@@ -2001,7 +2014,7 @@ public class WebMail extends HttpServlet
}
state = processStateChangeButtons(sessionObject, request, isPOST, state);
state = processConfigButtons(sessionObject, request, isPOST, state);
Debug.debug(Debug.DEBUG, "Prelim. state is " + state);
if (_log.shouldDebug()) _log.debug("Prelim. state is " + state);
if (state == State.CONFIG) {
if (isPOST) {
// P-R-G
@@ -2034,7 +2047,7 @@ public class WebMail extends HttpServlet
// int oldIdle = httpSession.getMaxInactiveInterval();
// httpSession.setMaxInactiveInterval(60*60*24); // seconds
// int newIdle = httpSession.getMaxInactiveInterval();
// Debug.debug(Debug.DEBUG, "Changed idle from " + oldIdle + " to " + newIdle);
// if (_log.shouldDebug()) _log.debug("Changed idle from " + oldIdle + " to " + newIdle);
//}
if( state != State.AUTH ) {
@@ -2160,7 +2173,7 @@ public class WebMail extends HttpServlet
try {
sessionObject.wait(5000);
} catch (InterruptedException ie) {
Debug.debug(Debug.DEBUG, "Interrupted waiting for load", ie);
if (_log.shouldDebug()) _log.debug("Interrupted waiting for load", ie);
}
}
if ((state == State.LIST || state == State.SHOW) && mc.isLoading())
@@ -2170,7 +2183,7 @@ public class WebMail extends HttpServlet
Folder<String> folder = mc != null ? mc.getFolder() : null;
//// End state determination, state will not change after here
Debug.debug(Debug.DEBUG, "Final state is " + state);
if (_log.shouldDebug()) _log.debug("Final state is " + state);
if (state == State.LIST || state == State.SHOW) {
// mc non-null
@@ -2393,7 +2406,7 @@ public class WebMail extends HttpServlet
resp.setHeader("Location", buf.toString());
resp.setStatus(303);
resp.getOutputStream().close();
Debug.debug(Debug.DEBUG, "P-R-G to " + q);
//if (_log.shouldDebug()) _log.debug("P-R-G to " + q);
}
/**
@@ -2415,6 +2428,7 @@ public class WebMail extends HttpServlet
{
boolean shown = false;
if(part != null) {
Log log = sessionObject.log;
String name = part.filename;
if (name == null) {
name = part.name;
@@ -2435,11 +2449,11 @@ public class WebMail extends HttpServlet
response.setContentType(part.type);
if (part.decodedLength >= 0)
response.setContentLength(part.decodedLength);
Debug.debug(Debug.DEBUG, "Sending raw attachment " + name + " length " + part.decodedLength);
if (log.shouldDebug()) log.debug("Sending raw attachment " + name + " length " + part.decodedLength);
part.decode(0, new OutputStreamBuffer(response.getOutputStream()));
shown = true;
} catch (IOException e) {
Debug.debug(Debug.ERROR, "Error sending raw attachment " + name + " length " + part.decodedLength, e);
log.error("Error sending raw attachment " + name + " length " + part.decodedLength, e);
}
} else {
ZipOutputStream zip = null;
@@ -2456,7 +2470,7 @@ public class WebMail extends HttpServlet
zip.finish();
shown = true;
} catch (IOException e) {
Debug.debug(Debug.ERROR, "Error sending zip attachment " + name + " length " + part.decodedLength, e);
log.error("Error sending zip attachment " + name + " length " + part.decodedLength, e);
} finally {
if ( zip != null)
try { zip.close(); } catch (IOException ioe) {}
@@ -2500,7 +2514,8 @@ public class WebMail extends HttpServlet
DataHelper.copy(in, response.getOutputStream());
return true;
} catch (IOException e) {
Debug.debug(Debug.DEBUG, "Save-As", e);
Log log = sessionObject.log;
if (log.shouldDebug()) log.debug("Save-As", e);
return false;
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
@@ -2582,12 +2597,13 @@ public class WebMail extends HttpServlet
Mail.appendRecipients( body, ccList, "Cc: " );
// only for draft
Mail.appendRecipients(body, bccList, Draft.HDR_BCC);
Log log = sessionObject.log;
try {
body.append(hl.encode("Subject: " + subject));
} catch (EncodingException e) {
ok = false;
sessionObject.error += e.getMessage() + '\n';
Debug.debug(Debug.DEBUG, "Draft subj", e);
if (log.shouldDebug()) log.debug("Draft subj", e);
}
body.append("MIME-Version: 1.0\r\nContent-type: text/plain; charset=\"utf-8\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n");
try {
@@ -2598,7 +2614,7 @@ public class WebMail extends HttpServlet
} catch (EncodingException e) {
ok = false;
sessionObject.error += e.getMessage() + '\n';
Debug.debug(Debug.DEBUG, "Draft body", e);
if (log.shouldDebug()) log.debug("Draft body", e);
}
}
return ok ? body : null;
@@ -2739,11 +2755,12 @@ public class WebMail extends HttpServlet
}
public void run() {
Debug.debug(Debug.DEBUG, "Email send start");
Log log = sessionObject.log;
if (log.shouldDebug()) log.debug("Email send start");
SMTPClient relay = new SMTPClient();
boolean ok = relay.sendMail(host, port, user, pass, sender, recipients, body,
attachments, boundary);
Debug.debug(Debug.DEBUG, "Email send complete, success? " + ok);
if (log.shouldDebug()) log.debug("Email send complete, success? " + ok);
synchronized(sessionObject) {
if (ok) {
sessionObject.info += _t("Mail sent.") + '\n';
@@ -2754,7 +2771,7 @@ public class WebMail extends HttpServlet
waitForLoad(sessionObject, mc);
mc.delete(draft.uidl);
mc.getFolder().removeElement(draft.uidl);
Debug.debug(Debug.DEBUG, "Sent email deleted from drafts");
if (log.shouldDebug()) log.debug("Sent email deleted from drafts");
}
// now store to sent
mc = sessionObject.caches.get(DIR_SENT);
@@ -2770,11 +2787,11 @@ public class WebMail extends HttpServlet
wout = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), "ISO-8859-1"));
SMTPClient.writeMail(wout, body,
attachments, boundary);
Debug.debug(Debug.DEBUG, "Sent email saved to Sent");
if (log.shouldDebug()) log.debug("Sent email saved to Sent");
copyOK = true;
} catch (IOException ioe) {
sessionObject.error += _t("Unable to save mail.") + ' ' + ioe.getMessage() + '\n';
Debug.debug(Debug.DEBUG, "Sent email saved error", ioe);
if (log.shouldDebug()) log.debug("Sent email saved error", ioe);
} finally {
if (wout != null) try { wout.close(); } catch (IOException ioe) {}
if (buffer != null)
@@ -2863,7 +2880,8 @@ public class WebMail extends HttpServlet
return;
}
String newUIDL = Base64.decodeToString(b64UIDL);
Debug.debug(Debug.DEBUG, "Show draft: " + newUIDL);
Log log = sessionObject.log;
if (log.shouldDebug()) log.debug("Show draft: " + newUIDL);
if (newUIDL != null)
draft = (Draft) drafts.getMail(newUIDL, MailCache.FetchMode.CACHE_ONLY);
if (draft != null) {
@@ -3101,7 +3119,7 @@ public class WebMail extends HttpServlet
if( sessionObject.clear )
idChecked = false;
//Debug.debug( Debug.DEBUG, "check" + i + ": checkId=" + checkId + ", idChecked=" + idChecked + ", pageChanged=" + sessionObject.pageChanged +
//if (_log.shouldDebug()) _log.debug("check" + i + ": checkId=" + checkId + ", idChecked=" + idChecked + ", pageChanged=" + sessionObject.pageChanged +
// ", markAll=" + sessionObject.markAll +
// ", invert=" + sessionObject.invert +
// ", clear=" + sessionObject.clear );
@@ -3243,7 +3261,8 @@ public class WebMail extends HttpServlet
"</p>");
}
Mail mail = mc.getMail(showUIDL, MailCache.FetchMode.ALL);
if(!RELEASE && mail != null && mail.hasBody() && mail.getSize() < 16384) {
boolean debug = Boolean.parseBoolean(Config.getProperty(CONFIG_DEBUG));
if(debug && mail != null && mail.hasBody() && mail.getSize() < 16384) {
out.println( "<!--" );
out.println( "Debug: Mail header and body follow");
Buffer body = mail.getBody();

View File

@@ -32,7 +32,9 @@ import i2p.susi.util.Buffer;
import i2p.susi.util.ReadBuffer;
import i2p.susi.util.MemoryBuffer;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;
/**
* Interface to encode/decode content transfer encodings like quoted-printable, base64 etc.
@@ -41,6 +43,12 @@ import net.i2p.data.DataHelper;
* @since 0.9.33 changed from interface to abstract class
*/
public abstract class Encoding {
protected final Log _log;
protected Encoding() {
_log = I2PAppContext.getGlobalContext().logManager().getLog(getClass());
}
public abstract String getName();
/**

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail.encoding;
import i2p.susi.debug.Debug;
import i2p.susi.util.Config;
import i2p.susi.util.Buffer;
@@ -32,8 +31,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.HexDump;
import net.i2p.util.Log;
/**
* Manager class to handle content transfer encodings.
@@ -58,10 +59,11 @@ public class EncodingFactory {
Class<?> c = Class.forName( classNames[i] );
Encoding e = (Encoding) (c.getDeclaredConstructor().newInstance());
encodings.put( e.getName(), e );
//Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() );
//if (_log.shouldDebug()) _log.debug("Registered " + e.getClass().getName() );
}
catch (Exception e) {
Debug.debug( Debug.ERROR, "Error loading class '" + classNames[i] + "', reason: " + e.getClass().getName() );
Log log = I2PAppContext.getGlobalContext().logManager().getLog(EncodingFactory.class);
log.error("Error loading class '" + classNames[i] + "'", e);
}
}
}

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail.encoding;
import i2p.susi.debug.Debug;
import i2p.susi.util.HexTable;
import i2p.susi.util.Buffer;
import i2p.susi.util.ReadBuffer;
@@ -36,6 +35,7 @@ import java.io.OutputStream;
import java.util.Locale;
import net.i2p.data.DataHelper;
import net.i2p.util.Log;
/**
* Ref:
@@ -232,7 +232,7 @@ public class HeaderLine extends Encoding {
if (hasPushback) {
c = pushbackChar;
hasPushback = false;
//Debug.debug(Debug.DEBUG, "Loop " + count + " Using pbchar(dec) " + c);
//if (_log.shouldDebug()) _log.debug("Loop " + count + " Using pbchar(dec) " + c);
} else {
c = in.read();
if (c < 0)
@@ -288,7 +288,7 @@ public class HeaderLine extends Encoding {
}
}
//if (f1 > 0)
// Debug.debug(Debug.DEBUG, "End of encoded word, f1 " + f1 + " f2 " + f2 + " f3 " + f3 + " f4 " + f4 +
// if (_log.shouldDebug()) _log.debug("End of encoded word, f1 " + f1 + " f2 " + f2 + " f3 " + f3 + " f4 " + f4 +
// " offset " + offset + " pushback? " + hasPushback + " pbchar(dec) " + c + '\n' +
// net.i2p.util.HexDump.dump(encodedWord, 0, offset));
if (f4 == 0) {
@@ -299,20 +299,20 @@ public class HeaderLine extends Encoding {
} else if (f2 == 0) {
// =? but no more ?
// output what we buffered
Debug.debug(Debug.DEBUG, "2nd '?' not found");
if (_log.shouldDebug()) _log.debug("2nd '?' not found");
for (int i = 0; i < offset; i++) {
out.write(encodedWord[i] & 0xff);
}
continue;
} else if (f3 == 0) {
// discard what we buffered
Debug.debug(Debug.DEBUG, "3rd '?' not found");
if (_log.shouldDebug()) _log.debug("3rd '?' not found");
continue;
} else {
// probably just too long, but could be end of line without the "?=".
// synthesize a 4th '?' in an attempt to output
// something, probably with some trailing garbage
Debug.debug(Debug.DEBUG, "4th '?' not found");
if (_log.shouldDebug()) _log.debug("4th '?' not found");
f4 = offset + 1;
// keep going and output what we have
}
@@ -339,9 +339,9 @@ public class HeaderLine extends Encoding {
} catch (EOFException eof) {
// probably Base64 exceeded DECODE_MAX
// Keep going and output what we got, if any
if (Debug.getLevel() >= Debug.DEBUG) {
Debug.debug(Debug.DEBUG, "q-w " + enc, eof);
Debug.debug(Debug.DEBUG, net.i2p.util.HexDump.dump(encodedWord));
if (_log.shouldDebug()) {
_log.debug("q-w " + enc, eof);
_log.debug(net.i2p.util.HexDump.dump(encodedWord));
}
}
tmp.writeComplete(true);
@@ -377,22 +377,22 @@ public class HeaderLine extends Encoding {
lastCharWasQuoted = true;
continue;
} catch (IOException e1) {
Debug.debug(Debug.ERROR, "q-w " + enc, e1);
if (Debug.getLevel() >= Debug.DEBUG) {
Debug.debug(Debug.DEBUG, net.i2p.util.HexDump.dump(encodedWord));
_log.error("q-w " + enc, e1);
if (_log.shouldDebug()) {
_log.debug(net.i2p.util.HexDump.dump(encodedWord));
}
} catch (RuntimeException e1) {
Debug.debug(Debug.ERROR, "q-w " + enc, e1);
if (Debug.getLevel() >= Debug.DEBUG) {
Debug.debug(Debug.DEBUG, net.i2p.util.HexDump.dump(encodedWord));
_log.error("q-w " + enc, e1);
if (_log.shouldDebug()) {
_log.debug(net.i2p.util.HexDump.dump(encodedWord));
}
}
} else {
// can't happen
Debug.debug(Debug.DEBUG, "No decoder for " + enc);
if (_log.shouldDebug()) _log.debug("No decoder for " + enc);
} // e != null
} else {
Debug.debug(Debug.DEBUG, "Invalid encoding '" + (char) encodedWord[f2+1] + '\'');
if (_log.shouldDebug()) _log.debug("Invalid encoding '" + (char) encodedWord[f2+1] + '\'');
} // enc != null
} // c == '='
else if( c == '\r' ) {
@@ -403,7 +403,7 @@ public class HeaderLine extends Encoding {
linebreak = true;
} else {
// pushback?
Debug.debug(Debug.DEBUG, "No \\n after \\r");
if (_log.shouldDebug()) _log.debug("No \\n after \\r");
}
}
// swallow whitespace here if lastCharWasQuoted

View File

@@ -1,6 +1,5 @@
package i2p.susi.webmail.pop3;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.WebMail;
import i2p.susi.util.Config;
@@ -12,6 +11,7 @@ import java.util.Set;
import net.i2p.I2PAppContext;
import net.i2p.util.I2PAppThread;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
@@ -27,6 +27,7 @@ class BackgroundChecker {
private final SimpleTimer2.TimedEvent timer;
private volatile boolean isChecking;
private volatile boolean isDead;
private final Log _log;
private static final int DEFAULT_CHECK_MINUTES = 3*60;
private static final int MIN_CHECK_MINUTES = 15;
@@ -41,6 +42,7 @@ class BackgroundChecker {
this.mailbox = mailbox;
toDelete = new ConcurrentHashSet<String>();
timer = new Checker();
_log = I2PAppContext.getGlobalContext().logManager().getLog(BackgroundChecker.class);
}
public Collection<String> getQueued() {
@@ -53,14 +55,14 @@ class BackgroundChecker {
timer.cancel();
}
private static long getCheckTime() {
private long getCheckTime() {
int minutes = DEFAULT_CHECK_MINUTES;
String con = Config.getProperty(WebMail.CONFIG_CHECK_MINUTES);
if (con != null) {
try {
int mins = Integer.parseInt(con);
// allow shorter for testing
if (mins < MIN_CHECK_MINUTES && Debug.getLevel() != Debug.DEBUG)
if (mins < MIN_CHECK_MINUTES && !_log.shouldDebug())
mins = MIN_CHECK_MINUTES;
minutes = mins;
} catch (NumberFormatException nfe) {}
@@ -81,17 +83,17 @@ class BackgroundChecker {
long idle = System.currentTimeMillis() - mailbox.getLastActivity();
long last = System.currentTimeMillis() - mailbox.getLastChecked();
if (idle >= MIN_IDLE && last >= MIN_SINCE) {
Debug.debug(Debug.DEBUG, "Threading check for mail after " +
if (_log.shouldDebug()) _log.debug("Threading check for mail after " +
idle + " ms idle and " + last + " since last check");
Thread t = new Getter();
isChecking = true;
t.start();
} else {
Debug.debug(Debug.DEBUG, "Not checking after " +
if (_log.shouldDebug()) _log.debug("Not checking after " +
idle + " ms idle and " + last + " since last check");
}
} else {
Debug.debug(Debug.DEBUG, "Not checking, still connected");
if (_log.shouldDebug()) _log.debug("Not checking, still connected");
}
schedule(getCheckTime());
}
@@ -108,7 +110,7 @@ class BackgroundChecker {
if (mailbox.blockingConnectToServer()) {
int found = mailbox.getNumMails();
if (found > 0) {
Debug.debug(Debug.DEBUG, "Found " + found + " mails, calling listener");
if (_log.shouldDebug()) _log.debug("Found " + found + " mails, calling listener");
// may not really be new
mailbox.foundNewMail(true);
}

View File

@@ -1,7 +1,5 @@
package i2p.susi.webmail.pop3;
import i2p.susi.debug.Debug;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -10,6 +8,7 @@ import java.util.Set;
import net.i2p.I2PAppContext;
import net.i2p.util.I2PAppThread;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
@@ -26,6 +25,7 @@ class DelayedDeleter {
private final POP3MailBox mailbox;
private final Set<String> toDelete;
private final SimpleTimer2.TimedEvent timer;
private final Log _log;
private volatile boolean isDeleting;
private volatile boolean isDead;
@@ -36,6 +36,7 @@ class DelayedDeleter {
this.mailbox = mailbox;
toDelete = new ConcurrentHashSet<String>();
timer = new Checker();
_log = I2PAppContext.getGlobalContext().logManager().getLog(DelayedDeleter.class);
}
public void queueDelete(String uidl) {
@@ -68,16 +69,16 @@ class DelayedDeleter {
if (!toDelete.isEmpty() && !isDeleting) {
long idle = System.currentTimeMillis() - mailbox.getLastActivity();
if (idle >= MIN_IDLE) {
Debug.debug(Debug.DEBUG, "Threading delayed delete for " + toDelete.size() +
if (_log.shouldDebug()) _log.debug("Threading delayed delete for " + toDelete.size() +
" mails after " + idle + " ms idle");
Thread t = new Deleter();
isDeleting = true;
t.start();
} else {
Debug.debug(Debug.DEBUG, "Not deleting " + toDelete.size() + ", only idle " + idle);
if (_log.shouldDebug()) _log.debug("Not deleting " + toDelete.size() + ", only idle " + idle);
}
} else {
Debug.debug(Debug.DEBUG, "Nothing to delete");
if (_log.shouldDebug()) _log.debug("Nothing to delete");
}
schedule(CHECK_TIME);
}
@@ -93,7 +94,7 @@ class DelayedDeleter {
try {
List<String> uidls = new ArrayList<String>(toDelete);
Collection<String> deleted = mailbox.delete(uidls);
Debug.debug(Debug.DEBUG, "Deleted " + deleted.size() + " of " + toDelete.size() + " mails");
if (_log.shouldDebug()) _log.debug("Deleted " + deleted.size() + " of " + toDelete.size() + " mails");
toDelete.removeAll(deleted);
} finally {
isDeleting = false;

View File

@@ -1,11 +1,11 @@
package i2p.susi.webmail.pop3;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.WebMail;
import i2p.susi.util.Config;
import net.i2p.I2PAppContext;
import net.i2p.util.I2PAppThread;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
@@ -18,6 +18,7 @@ class IdleCloser {
private final POP3MailBox mailbox;
private final SimpleTimer2.TimedEvent timer;
private final Log _log;
private volatile boolean isClosing;
private volatile boolean isDead;
@@ -31,6 +32,7 @@ class IdleCloser {
public IdleCloser(POP3MailBox mailbox) {
this.mailbox = mailbox;
timer = new Checker();
_log = I2PAppContext.getGlobalContext().logManager().getLog(IdleCloser.class);
}
public void cancel() {
@@ -68,14 +70,15 @@ class IdleCloser {
long config = getMaxIdle();
long idle = System.currentTimeMillis() - mailbox.getLastActivity();
long remaining = config - idle;
Log log = IdleCloser.this._log;
if (remaining <= 0) {
Debug.debug(Debug.DEBUG, "Threading close after " +
if (log.shouldDebug()) log.debug("Threading close after " +
idle + " ms idle");
Thread t = new Closer();
isClosing = true;
t.start();
} else {
Debug.debug(Debug.DEBUG, "Not closing after " +
if (log.shouldDebug()) log.debug("Not closing after " +
idle + " ms idle");
schedule(remaining + 5000);
}

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail.pop3;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.Messages;
import i2p.susi.webmail.NewMailListener;
import i2p.susi.webmail.WebMail;
@@ -44,9 +43,11 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.I2PAppThread;
import net.i2p.util.InternalSocket;
import net.i2p.util.Log;
/**
* @author susi23
@@ -54,6 +55,7 @@ import net.i2p.util.InternalSocket;
public class POP3MailBox implements NewMailListener {
private final String host, user, pass;
private final Log _log;
private String lastLine, lastError;
@@ -92,9 +94,9 @@ public class POP3MailBox implements NewMailListener {
* @param pass
*/
public POP3MailBox(String host, int port, String user, String pass) {
Debug.debug(
Debug.DEBUG,
"Mailbox(" + host + "," + port + "," + user + ",password)");
_log = I2PAppContext.getGlobalContext().logManager().getLog(POP3MailBox.class);
if (_log.shouldDebug())
_log.debug("Mailbox(" + host + "," + port + "," + user + ",password)");
this.host = host;
this.port = port;
this.user = user;
@@ -121,7 +123,7 @@ public class POP3MailBox implements NewMailListener {
// we must be connected to know the UIDL to ID mapping
checkConnection();
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error fetching header", ioe);
if (_log.shouldDebug()) _log.debug("Error fetching header", ioe);
return null;
}
int id = getIDfromUIDL(uidl);
@@ -139,7 +141,7 @@ public class POP3MailBox implements NewMailListener {
* @return Byte buffer containing header data or null
*/
private Buffer getHeader( int id ) {
Debug.debug(Debug.DEBUG, "getHeader(" + id + ")");
if (_log.shouldDebug()) _log.debug("getHeader(" + id + ")");
Buffer header = null;
if (id >= 1 && id <= mails) {
try { socket.setSoTimeout(120*1000); } catch (IOException ioe) {}
@@ -153,7 +155,7 @@ public class POP3MailBox implements NewMailListener {
*/
header = sendCmdN("RETR " + id, new MemoryBuffer(2048));
if (header == null)
Debug.debug( Debug.DEBUG, "RETR returned null" );
if (_log.shouldDebug()) _log.debug("RETR returned null" );
}
if (socket != null) try { socket.setSoTimeout(300*1000); } catch (IOException ioe) {}
} else {
@@ -174,7 +176,7 @@ public class POP3MailBox implements NewMailListener {
// we must be connected to know the UIDL to ID mapping
checkConnection();
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error fetching body", ioe);
if (_log.shouldDebug()) _log.debug("Error fetching body", ioe);
return null;
}
int id = getIDfromUIDL(uidl);
@@ -198,7 +200,7 @@ public class POP3MailBox implements NewMailListener {
// we must be connected to know the UIDL to ID mapping
checkConnection();
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error fetching", ioe);
if (_log.shouldDebug()) _log.debug("Error fetching", ioe);
return;
}
for (FetchRequest fr : requests) {
@@ -220,7 +222,7 @@ public class POP3MailBox implements NewMailListener {
try {
sendCmds(srs);
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error fetching bodies", ioe);
if (_log.shouldDebug()) _log.debug("Error fetching bodies", ioe);
if (socket != null) {
try { socket.close(); } catch (IOException e) {}
socket = null;
@@ -243,7 +245,7 @@ public class POP3MailBox implements NewMailListener {
* @return the buffer containing body data or null
*/
private Buffer getBody(int id, Buffer buffer) {
Debug.debug(Debug.DEBUG, "getBody(" + id + ")");
if (_log.shouldDebug()) _log.debug("getBody(" + id + ")");
Buffer body = null;
if (id >= 1 && id <= mails) {
try {
@@ -251,9 +253,9 @@ public class POP3MailBox implements NewMailListener {
body = sendCmdN("RETR " + id, buffer);
if (socket != null) try { socket.setSoTimeout(300*1000); } catch (IOException ioe) {}
if (body == null)
Debug.debug( Debug.DEBUG, "RETR returned null" );
if (_log.shouldDebug()) _log.debug("RETR returned null" );
} catch (OutOfMemoryError oom) {
Debug.debug( Debug.ERROR, "OOM fetching mail" );
_log.error("OOM fetching mail", oom);
lastError = oom.toString();
close();
}
@@ -274,13 +276,13 @@ public class POP3MailBox implements NewMailListener {
/****
public boolean delete( String uidl )
{
Debug.debug(Debug.DEBUG, "delete(" + uidl + ")");
if (_log.shouldDebug()) _log.debug("delete(" + uidl + ")");
synchronized( synchronizer ) {
try {
// we must be connected to know the UIDL to ID mapping
checkConnection();
} catch (IOException ioe) {
Debug.debug( Debug.DEBUG, "Error deleting: " + ioe);
if (_log.shouldDebug()) _log.debug("Error deleting: " + ioe);
return false;
}
int id = getIDfromUIDL(uidl);
@@ -308,7 +310,7 @@ public class POP3MailBox implements NewMailListener {
* @since 0.9.13
*/
public void queueForDeletion(String uidl) {
Debug.debug(Debug.DEBUG, "Queueing for deletion: " + uidl);
if (_log.shouldDebug()) _log.debug("Queueing for deletion: " + uidl);
delayedDeleter.queueDelete(uidl);
}
@@ -327,7 +329,7 @@ public class POP3MailBox implements NewMailListener {
// we must be connected to know the UIDL to ID mapping
checkConnection();
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error deleting", ioe);
if (_log.shouldDebug()) _log.debug("Error deleting", ioe);
return rv;
}
for (String uidl : uidls) {
@@ -368,7 +370,7 @@ public class POP3MailBox implements NewMailListener {
// why reconnect?
//connect();
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error deleting", ioe);
if (_log.shouldDebug()) _log.debug("Error deleting", ioe);
if (socket != null) {
try { socket.close(); } catch (IOException e) {}
socket = null;
@@ -390,7 +392,7 @@ public class POP3MailBox implements NewMailListener {
/****
private boolean delete(int id)
{
Debug.debug(Debug.DEBUG, "delete(" + id + ")");
if (_log.shouldDebug()) _log.debug("delete(" + id + ")");
boolean result = false;
@@ -436,7 +438,7 @@ public class POP3MailBox implements NewMailListener {
Integer resultObj = sizes.get(Integer.valueOf(id));
if (resultObj != null)
result = resultObj.intValue();
Debug.debug(Debug.DEBUG, "getSize(" + id + ") = " + result);
if (_log.shouldDebug()) _log.debug("getSize(" + id + ") = " + result);
return result;
}
@@ -468,7 +470,7 @@ public class POP3MailBox implements NewMailListener {
* @return true or false
*/
private void checkConnection() throws IOException {
Debug.debug(Debug.DEBUG, "checkConnection()");
if (_log.shouldDebug()) _log.debug("checkConnection()");
if (!isConnected()) {
connect();
if (!isConnected())
@@ -541,15 +543,15 @@ public class POP3MailBox implements NewMailListener {
String uidl = line.substring(j + 1).trim();
uidlToID.put( uidl, Integer.valueOf( n ) );
} catch (NumberFormatException nfe) {
Debug.debug(Debug.DEBUG, "UIDL error", nfe);
if (_log.shouldDebug()) _log.debug("UIDL error", nfe);
} catch (IndexOutOfBoundsException ioobe) {
Debug.debug(Debug.DEBUG, "UIDL error", ioobe);
if (_log.shouldDebug()) _log.debug("UIDL error", ioobe);
}
}
}
lastChecked.set(System.currentTimeMillis());
} else {
Debug.debug(Debug.DEBUG, "Error getting UIDL list from server.");
if (_log.shouldDebug()) _log.debug("Error getting UIDL list from server.");
}
}
@@ -572,12 +574,12 @@ public class POP3MailBox implements NewMailListener {
int value = Integer.parseInt(line.substring(j + 1).trim());
sizes.put(Integer.valueOf(key), Integer.valueOf(value));
} catch (NumberFormatException nfe) {
Debug.debug(Debug.DEBUG, "LIST error", nfe);
if (_log.shouldDebug()) _log.debug("LIST error", nfe);
}
}
}
} else {
Debug.debug(Debug.DEBUG, "Error getting LIST from server.");
if (_log.shouldDebug()) _log.debug("Error getting LIST from server.");
}
}
@@ -676,7 +678,7 @@ public class POP3MailBox implements NewMailListener {
socket = null;
connected = false;
}
Debug.debug(Debug.DEBUG, "Error rechecking", e1);
if (_log.shouldDebug()) _log.debug("Error rechecking", e1);
} catch (IOException e1) {
if (socket != null) {
try { socket.close(); } catch (IOException e) {}
@@ -684,7 +686,7 @@ public class POP3MailBox implements NewMailListener {
connected = false;
}
lastError = _t("Cannot connect") + ": " + e1.getLocalizedMessage();
Debug.debug(Debug.DEBUG, "Error rechecking", e1);
if (_log.shouldDebug()) _log.debug("Error rechecking", e1);
// we probably weren't really connected.
// Let's try again from the top.
result = blockingConnectToServer();
@@ -731,9 +733,7 @@ public class POP3MailBox implements NewMailListener {
* Caller must sync.
*/
private void connect() {
Debug.debug(Debug.DEBUG, "connect()");
if (Debug.getLevel() == Debug.DEBUG)
(new Exception("I did it")).printStackTrace();
if (_log.shouldDebug()) _log.debug("connect()", new Exception("I did it"));
clear();
@@ -743,7 +743,7 @@ public class POP3MailBox implements NewMailListener {
try {
socket = InternalSocket.getSocket(host, port);
} catch (IOException e) {
Debug.debug(Debug.DEBUG, "Error connecting", e);
if (_log.shouldDebug()) _log.debug("Error connecting", e);
lastError = _t("Cannot connect") + " (" + host + ':' + port + ") - " + e.getLocalizedMessage();
return;
}
@@ -788,7 +788,7 @@ public class POP3MailBox implements NewMailListener {
socket = null;
connected = false;
}
Debug.debug(Debug.DEBUG, "Error connecting", e1);
if (_log.shouldDebug()) _log.debug("Error connecting", e1);
} catch (IOException e1) {
lastError = _t("Cannot connect") + ": " + e1.getLocalizedMessage();
if (socket != null) {
@@ -796,7 +796,7 @@ public class POP3MailBox implements NewMailListener {
socket = null;
connected = false;
}
Debug.debug(Debug.DEBUG, "Error connecting", e1);
if (_log.shouldDebug()) _log.debug("Error connecting", e1);
}
}
}
@@ -814,7 +814,7 @@ public class POP3MailBox implements NewMailListener {
cmds.add(new SendRecv(null, Mode.A1));
SendRecv capa = null;
if (gotCAPA) {
Debug.debug(Debug.DEBUG, "Skipping CAPA");
if (_log.shouldDebug()) _log.debug("Skipping CAPA");
} else {
capa = new SendRecv("CAPA", Mode.LS);
cmds.add(capa);
@@ -833,7 +833,7 @@ public class POP3MailBox implements NewMailListener {
}
}
gotCAPA = true;
Debug.debug(Debug.DEBUG, "POP3 server caps: pipelining? " + supportsPipelining +
if (_log.shouldDebug()) _log.debug("POP3 server caps: pipelining? " + supportsPipelining +
" UIDL? " + supportsUIDL +
" TOP? " + supportsTOP);
}
@@ -865,15 +865,15 @@ public class POP3MailBox implements NewMailListener {
if (stat.result)
updateMailCount(stat.response);
else
Debug.debug(Debug.DEBUG, "STAT failed");
if (_log.shouldDebug()) _log.debug("STAT failed");
if (uidl.result)
updateUIDLs(uidl.ls);
else
Debug.debug(Debug.DEBUG, "UIDL failed");
if (_log.shouldDebug()) _log.debug("UIDL failed");
if (list.result)
updateSizes(list.ls);
else
Debug.debug(Debug.DEBUG, "LIST failed");
if (_log.shouldDebug()) _log.debug("LIST failed");
if (socket != null) try { socket.setSoTimeout(300*1000); } catch (IOException ioe) {}
return ok;
}
@@ -893,22 +893,22 @@ public class POP3MailBox implements NewMailListener {
socket.getOutputStream().flush();
String foo = DataHelper.readLine(socket.getInputStream());
updateActivity();
// Debug.debug(Debug.DEBUG, "sendCmd1a: read " + read + " bytes");
// if (_log.shouldDebug()) _log.debug("sendCmd1a: read " + read + " bytes");
if (foo != null) {
lastLine = foo;
if (lastLine.startsWith("+OK")) {
if (cmd.startsWith("PASS"))
cmd = "PASS provided";
Debug.debug(Debug.DEBUG, "sendCmd1a: (" + cmd + ") success: \"" + lastLine.trim() + '"');
if (_log.shouldDebug()) _log.debug("sendCmd1a: (" + cmd + ") success: \"" + lastLine.trim() + '"');
result = true;
} else {
if (cmd.startsWith("PASS"))
cmd = "PASS provided";
Debug.debug(Debug.DEBUG, "sendCmd1a: (" + cmd + ") FAIL: \"" + lastLine.trim() + '"');
if (_log.shouldDebug()) _log.debug("sendCmd1a: (" + cmd + ") FAIL: \"" + lastLine.trim() + '"');
lastError = lastLine;
}
} else {
Debug.debug(Debug.DEBUG, "sendCmd1a: (" + cmd + ") NO RESPONSE");
if (_log.shouldDebug()) _log.debug("sendCmd1a: (" + cmd + ") NO RESPONSE");
lastError = _t("No response from server");
throw new IOException(lastError);
}
@@ -930,7 +930,7 @@ public class POP3MailBox implements NewMailListener {
boolean result = true;
boolean pipe = supportsPipelining;
if (pipe) {
Debug.debug(Debug.DEBUG, "POP3 pipelining " + cmds.size() + " commands");
if (_log.shouldDebug()) _log.debug("POP3 pipelining " + cmds.size() + " commands");
for (SendRecv sr : cmds) {
String cmd = sr.send;
if (cmd != null)
@@ -957,13 +957,13 @@ public class POP3MailBox implements NewMailListener {
sr.response = foo.trim();
i++;
if (!foo.startsWith("+OK")) {
Debug.debug(Debug.DEBUG, "Fail after " + i + " of " + cmds.size() + " responses: \"" + foo.trim() + '"');
if (_log.shouldDebug()) _log.debug("Fail after " + i + " of " + cmds.size() + " responses: \"" + foo.trim() + '"');
if (result)
lastError = foo; // actually the first error, for better info to the user
result = false;
sr.result = false;
} else {
Debug.debug(Debug.DEBUG, "OK after " + i + " of " + cmds.size() + " responses: \"" + foo.trim() + '"');
if (_log.shouldDebug()) _log.debug("OK after " + i + " of " + cmds.size() + " responses: \"" + foo.trim() + '"');
switch (sr.mode) {
case A1:
sr.result = true;
@@ -974,7 +974,7 @@ public class POP3MailBox implements NewMailListener {
getResultNa(sr.rb);
sr.result = true;
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error getting RB", ioe);
if (_log.shouldDebug()) _log.debug("Error getting RB", ioe);
result = false;
sr.result = false;
if (socket != null) {
@@ -990,7 +990,7 @@ public class POP3MailBox implements NewMailListener {
sr.ls = getResultNl();
sr.result = true;
} catch (IOException ioe) {
Debug.debug(Debug.DEBUG, "Error getting LS", ioe);
if (_log.shouldDebug()) _log.debug("Error getting LS", ioe);
result = false;
sr.result = false;
if (socket != null) {
@@ -1022,7 +1022,7 @@ public class POP3MailBox implements NewMailListener {
String msg = cmd;
if (msg.startsWith("PASS"))
msg = "PASS provided";
Debug.debug(Debug.DEBUG, "sendCmd1a(" + msg + ")");
if (_log.shouldDebug()) _log.debug("sendCmd1a(" + msg + ")");
cmd += "\r\n";
socket.getOutputStream().write(DataHelper.getASCII(cmd));
updateActivity();
@@ -1041,7 +1041,7 @@ public class POP3MailBox implements NewMailListener {
return sendCmdNa(cmd, buffer);
} catch (IOException e) {
lastError = e.toString();
Debug.debug(Debug.DEBUG, "sendCmdNa throws", e);
if (_log.shouldDebug()) _log.debug("sendCmdNa throws", e);
if (socket != null) {
try { socket.close(); } catch (IOException ioe) {}
socket = null;
@@ -1054,7 +1054,7 @@ public class POP3MailBox implements NewMailListener {
return sendCmdNa(cmd, buffer);
} catch (IOException e2) {
lastError = e2.toString();
Debug.debug(Debug.DEBUG, "2nd sendCmdNa throws", e2);
if (_log.shouldDebug()) _log.debug("2nd sendCmdNa throws", e2);
if (socket != null) {
try { socket.close(); } catch (IOException e) {}
socket = null;
@@ -1062,7 +1062,7 @@ public class POP3MailBox implements NewMailListener {
}
}
} else {
Debug.debug( Debug.DEBUG, "not connected after reconnect" );
if (_log.shouldDebug()) _log.debug("not connected after reconnect" );
}
}
return null;
@@ -1081,7 +1081,7 @@ public class POP3MailBox implements NewMailListener {
getResultNa(buffer);
return buffer;
} else {
Debug.debug( Debug.DEBUG, "sendCmd1a returned false" );
if (_log.shouldDebug()) _log.debug("sendCmd1a returned false" );
return null;
}
}
@@ -1101,7 +1101,7 @@ public class POP3MailBox implements NewMailListener {
if (sendCmd1a(cmd)) {
return getResultNl();
} else {
Debug.debug( Debug.DEBUG, "sendCmd1a returned false" );
if (_log.shouldDebug()) _log.debug("sendCmd1a returned false" );
return null;
}
}
@@ -1192,7 +1192,7 @@ public class POP3MailBox implements NewMailListener {
*/
public int getNumMails() {
synchronized( synchronizer ) {
Debug.debug(Debug.DEBUG, "getNumMails()");
if (_log.shouldDebug()) _log.debug("getNumMails()");
try {
checkConnection();
} catch (IOException ioe) {}
@@ -1204,7 +1204,7 @@ public class POP3MailBox implements NewMailListener {
* @return The most recent error message. Probably not terminated with a newline.
*/
public String lastError() {
//Debug.debug(Debug.DEBUG, "lastError()");
//if (_log.shouldDebug()) _log.debug("lastError()");
// Hide the "-ERR" from the user
String e = lastError;
if (e.startsWith("-ERR ") && e.length() > 5)
@@ -1286,7 +1286,7 @@ public class POP3MailBox implements NewMailListener {
*/
void close(boolean shouldWait) {
synchronized( synchronizer ) {
Debug.debug(Debug.DEBUG, "close()");
if (_log.shouldDebug()) _log.debug("close()");
if (idleCloser != null)
idleCloser.cancel();
if (socket != null && socket.isConnected()) {
@@ -1310,7 +1310,7 @@ public class POP3MailBox implements NewMailListener {
} else {
sendCmd1a("QUIT");
}
Debug.debug( Debug.DEBUG, "close() with wait complete");
if (_log.shouldDebug()) _log.debug("close() with wait complete");
} else {
if (!sendDelete.isEmpty()) {
// spray and pray the deletions, don't remove from delete queue
@@ -1321,7 +1321,7 @@ public class POP3MailBox implements NewMailListener {
sendCmd1aNoWait("QUIT");
}
} catch (IOException e) {
//Debug.debug( Debug.DEBUG, "error closing: " + e);
//if (_log.shouldDebug()) _log.debug("error closing: " + e);
} finally {
if (socket != null) {
try { socket.close(); } catch (IOException e) {}
@@ -1391,7 +1391,6 @@ public class POP3MailBox implements NewMailListener {
/****
public static void main( String[] args )
{
Debug.setLevel( Debug.DEBUG );
POP3MailBox mailbox = new POP3MailBox( "localhost", 7660 , "test", "test");
ReadBuffer readBuffer = mailbox.sendCmdN( "LIST" );
System.out.println( "list='" + readBuffer + "'" );

View File

@@ -23,7 +23,6 @@
*/
package i2p.susi.webmail.smtp;
import i2p.susi.debug.Debug;
import i2p.susi.webmail.Attachment;
import i2p.susi.webmail.Messages;
import i2p.susi.webmail.encoding.Encoding;
@@ -41,8 +40,10 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
import net.i2p.util.InternalSocket;
import net.i2p.util.Log;
/**
* @author susi
@@ -63,6 +64,7 @@ public class SMTPClient {
*/
public static final long BINARY_MAX_SIZE = (long) ((DEFAULT_MAX_SIZE * 57.0d / 78) - 32*1024);
private final Log _log;
private Socket socket;
public String error;
private String lastResponse;
@@ -79,6 +81,7 @@ public class SMTPClient {
{
error = "";
lastResponse = "";
_log = I2PAppContext.getGlobalContext().logManager().getLog(SMTPClient.class);
}
/**
@@ -121,7 +124,7 @@ public class SMTPClient {
*/
private void sendCmdNoWait(String cmd) throws IOException
{
Debug.debug( Debug.DEBUG, "SMTP sendCmd(" + cmd +")" );
if (_log.shouldDebug()) _log.debug("SMTP sendCmd(" + cmd +")" );
if( socket == null )
throw new IOException("no socket");
@@ -141,7 +144,7 @@ public class SMTPClient {
{
int rv = 0;
if (supportsPipelining) {
Debug.debug(Debug.DEBUG, "SMTP pipelining " + cmds.size() + " commands");
if (_log.shouldDebug()) _log.debug("SMTP pipelining " + cmds.size() + " commands");
try {
for (SendExpect cmd : cmds) {
sendCmdNoWait(cmd.send);
@@ -168,7 +171,7 @@ public class SMTPClient {
rv++;
}
}
Debug.debug(Debug.DEBUG, "SMTP success in " + rv + " of " + cmds.size() + " commands");
if (_log.shouldDebug()) _log.debug("SMTP success in " + rv + " of " + cmds.size() + " commands");
return rv;
}
@@ -193,7 +196,7 @@ public class SMTPClient {
InputStream in = socket.getInputStream();
StringBuilder buf = new StringBuilder(128);
while (DataHelper.readLine(in, buf)) {
Debug.debug(Debug.DEBUG, "SMTP rcv \"" + buf.toString().trim() + '"');
if (_log.shouldDebug()) _log.debug("SMTP rcv \"" + buf.toString().trim() + '"');
int len = buf.length();
if (len < 4) {
result = 0;
@@ -266,16 +269,16 @@ public class SMTPClient {
for (String c : caps) {
if (c.equals("PIPELINING")) {
supportsPipelining = true;
Debug.debug(Debug.DEBUG, "Server supports pipelining");
if (_log.shouldDebug()) _log.debug("Server supports pipelining");
} else if (c.startsWith("SIZE ")) {
try {
maxSize = Long.parseLong(c.substring(5));
Debug.debug(Debug.DEBUG, "Server max size: " + maxSize);
if (_log.shouldDebug()) _log.debug("Server max size: " + maxSize);
} catch (NumberFormatException nfe) {}
} else if (c.equals("8BITMIME")) {
// unused, see encoding/EightBit.java
eightBitMime = true;
Debug.debug(Debug.DEBUG, "Server supports 8bitmime");
if (_log.shouldDebug()) _log.debug("Server supports 8bitmime");
}
}
} else {
@@ -284,7 +287,7 @@ public class SMTPClient {
}
}
if (ok && maxSize < DEFAULT_MAX_SIZE) {
Debug.debug(Debug.DEBUG, "Rechecking with new max size");
if (_log.shouldDebug()) _log.debug("Rechecking with new max size");
// recalculate whether we'll fit
// copied from WebMail
long total = body.length();