public TracingWakeLock(int flags, String ntag) { tag = ntag; wakeLock = pm.newWakeLock(flags, tag); id = wakeLockId.getAndIncrement(); if (K9MailLib.isDebug()) { Timber.v("TracingWakeLock for tag %s / id %d: Create", tag, id); } }
private void writeLine(String s, boolean sensitive) throws IOException { if (K9MailLib.isDebug() && DEBUG_PROTOCOL_SMTP) { final String commandToLog; if (sensitive && !K9MailLib.isDebugSensitive()) { commandToLog = "SMTP >>> *sensitive*"; } else { commandToLog = "SMTP >>> " + s; } Timber.d(commandToLog); } byte[] data = s.concat("\r\n").getBytes(); /* * Important: Send command + CRLF using just one write() call. Using * multiple calls will likely result in multiple TCP packets and some * SMTP servers misbehave if CR and LF arrive in separate pakets. * See issue 799. */ outputStream.write(data); outputStream.flush(); }
public static void init(Context context) { K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() { @Override public boolean enabled() { return DEBUG; } @Override public boolean debugSensitive() { return DEBUG_SENSITIVE; } }); checkCachedDatabaseVersion(context); Preferences prefs = DI.get(Preferences.class); loadPrefs(prefs); }
public List<ImapResponse> executeSimpleCommand(String command, boolean sensitive) throws IOException, MessagingException { String commandToLog = command; if (sensitive && !K9MailLib.isDebugSensitive()) { commandToLog = "*sensitive*"; } String tag = sendCommand(command, sensitive); try { return responseParser.readStatusResponse(tag, commandToLog, getLogId(), null); } catch (IOException e) { close(); throw e; } }
private void parseOptionalSizeValue(Map<String, String> extensions) { if (extensions.containsKey("SIZE")) { String optionalsizeValue = extensions.get("SIZE"); if (optionalsizeValue != null && !"".equals(optionalsizeValue)) { try { largestAcceptableMessage = Integer.parseInt(optionalsizeValue); } catch (NumberFormatException e) { if (K9MailLib.isDebug() && DEBUG_PROTOCOL_SMTP) { Timber.d(e, "Tried to parse %s and get an int", optionalsizeValue); } } } } }
public String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive) throws IOException, MessagingException { try { open(); String tag = Integer.toString(nextCommandTag++); String commandToSend = tag + " " + command + " " + initialClientResponse + "\r\n"; outputStream.write(commandToSend.getBytes()); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { if (sensitive && !K9MailLib.isDebugSensitive()) { Timber.v("%s>>> [Command Hidden, Enable Sensitive Debug Logging To Show]", getLogId()); } else { Timber.v("%s>>> %s %s %s", getLogId(), tag, command, initialClientResponse); } } return tag; } catch (IOException | MessagingException e) { close(); throw e; } }
@Override public void onCreate() { super.onCreate(); setupStrictMode(); gcmAvailable = GooglePlayServices.isAvailable(this); preferences = new Preferences(this); preferences.migrate(); backupJobs = new BackupJobs(this); if (gcmAvailable) { setBroadcastReceiversEnabled(false); } else { Log.v(TAG, "Google Play Services not available, forcing use of old scheduler"); preferences.setUseOldScheduler(true); } K9MailLib.setDebugStatus(new K9MailLib.DebugStatus() { @Override public boolean enabled() { return preferences.isAppLogDebug(); } @Override public boolean debugSensitive() { return false; } }); if (gcmAvailable && DEBUG) { getContentResolver().registerContentObserver(Consts.SMS_PROVIDER, true, new LoggingContentObserver()); getContentResolver().registerContentObserver(Consts.CALLLOG_PROVIDER, true, new LoggingContentObserver()); } register(this); }
public void sendContinuation(String continuation) throws IOException { outputStream.write(continuation.getBytes()); outputStream.write('\r'); outputStream.write('\n'); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { Timber.v("%s>>> %s", getLogId(), continuation); } }
public String sendCommand(String command, boolean sensitive) throws MessagingException, IOException { try { open(); String tag = Integer.toString(nextCommandTag++); String commandToSend = tag + " " + command + "\r\n"; outputStream.write(commandToSend.getBytes()); outputStream.flush(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_IMAP) { if (sensitive && !K9MailLib.isDebugSensitive()) { Timber.v("%s>>> [Command Hidden, Enable Sensitive Debug Logging To Show]", getLogId()); } else { Timber.v("%s>>> %s %s", getLogId(), tag, command); } } return tag; } catch (IOException | MessagingException e) { close(); throw e; } }
protected boolean isIdleCapable() { if (K9MailLib.isDebug()) { Timber.v("Connection %s has %d capabilities", getLogId(), capabilities.size()); } return capabilities.contains(Capabilities.IDLE); }
private String executeSimpleCommand(String command, boolean sensitive) throws MessagingException { try { if (command != null) { if (K9MailLib.isDebug() && DEBUG_PROTOCOL_POP3) { if (sensitive && !K9MailLib.isDebugSensitive()) { Timber.d(">>> [Command Hidden, Enable Sensitive Debug Logging To Show]"); } else { Timber.d(">>> %s", command); } } writeLine(command); } String response = readLine(); if (response.length() == 0 || response.charAt(0) != '+') { throw new Pop3ErrorResponse(response); } return response; } catch (MessagingException me) { throw me; } catch (Exception e) { close(); throw new MessagingException("Unable to execute POP3 command", e); } }
String readLine() throws IOException { StringBuilder sb = new StringBuilder(); int d = in.read(); if (d == -1) { throw new IOException("End of stream reached while trying to read line."); } do { if (((char)d) == '\r') { //noinspection UnnecessaryContinue Makes it easier to follow continue; } else if (((char)d) == '\n') { break; } else { sb.append((char)d); } } while ((d = in.read()) != -1); String ret = sb.toString(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_POP3) { Timber.d("<<< %s", ret); } return ret; }
private String readLine() throws IOException { StringBuilder sb = new StringBuilder(); int d; while ((d = inputStream.read()) != -1) { char c = (char) d; if (c == '\n') { break; } else if (c != '\r') { sb.append(c); } } String ret = sb.toString(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_SMTP) Timber.d("SMTP <<< %s", ret); return ret; }
public static synchronized TracingPowerManager getPowerManager(Context context) { Context appContext = context.getApplicationContext(); if (tracingPowerManager == null) { if (K9MailLib.isDebug()) { Timber.v("Creating TracingPowerManager"); } tracingPowerManager = new TracingPowerManager(appContext); } return tracingPowerManager; }
@Override public void acquire() { synchronized (wakeLock) { wakeLock.acquire(); } raiseNotification(); if (K9MailLib.isDebug()) { Timber.w("TracingWakeLock for tag %s / id %d: acquired with no timeout. K-9 Mail should not do this", tag, id); } if (startTime == null) { startTime = SystemClock.elapsedRealtime(); } timeout = null; }
@Override public void acquire(long timeout) { synchronized (wakeLock) { wakeLock.acquire(timeout); } if (K9MailLib.isDebug()) { Timber.v("TracingWakeLock for tag %s / id %d for %d ms: acquired", tag, id, timeout); } raiseNotification(); if (startTime == null) { startTime = SystemClock.elapsedRealtime(); } this.timeout = timeout; }
@Override public void release() { if (startTime != null) { Long endTime = SystemClock.elapsedRealtime(); if (K9MailLib.isDebug()) { Timber.v("TracingWakeLock for tag %s / id %d: releasing after %d ms, timeout = %d ms", tag, id, endTime - startTime, timeout); } } else { if (K9MailLib.isDebug()) { Timber.v("TracingWakeLock for tag %s / id %d, timeout = %d ms: releasing", tag, id, timeout); } } cancelNotification(); synchronized (wakeLock) { wakeLock.release(); } startTime = null; }
@Override public void open() throws MessagingException { if (K9MailLib.isDebug()) Timber.d( ">>> open called on WebDavTransport "); store.getHttpClient(); }
private long getNewUidNext() throws MessagingException { long newUidNext = uidNext; if (newUidNext != -1L) { return newUidNext; } if (K9MailLib.isDebug()) { Timber.d("uidNext is -1, using search to find highest UID"); } long highestUid = getHighestUid(); if (highestUid == -1L) { return -1L; } newUidNext = highestUid + 1; if (K9MailLib.isDebug()) { Timber.d("highest UID = %d, set newUidNext to %d", highestUid, newUidNext); } return newUidNext; }
public WebDavTransport(TrustManagerFactory trustManagerFactory, WebDavStoreSettings serverSettings, StoreConfig storeConfig) { store = new WebDavStore(trustManagerFactory, serverSettings, storeConfig); if (K9MailLib.isDebug()) Timber.d(">>> New WebDavTransport creation complete"); }