Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64c7df60 authored by cketti's avatar cketti
Browse files

Don't log sensitive information in SMTP commands when "Log sensitive

information" is unchecked. Applied patch by fiouzy with some small modifications.

Fixes issue 1387
parent 34a95ba0
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -415,10 +415,21 @@ public class SmtpTransport extends Transport
        return ret;
    }

    private void writeLine(String s) throws IOException
    private void writeLine(String s, boolean sensitive) throws IOException
    {
        if (K9.DEBUG)
            Log.d(K9.LOG_TAG, "SMTP >>> " + s);
        {
            final String commandToLog;
            if (sensitive && !K9.DEBUG_SENSITIVE)
            {
                commandToLog = "SMTP >>> *sensitive*";
            }
            else
            {
                commandToLog = "SMTP >>> " + s;
    		}
            Log.d(K9.LOG_TAG, commandToLog);
        }

        /*
         * Note: We can use the string length to compute the buffer size since
@@ -455,11 +466,17 @@ public class SmtpTransport extends Transport
    }

    private List<String> executeSimpleCommand(String command) throws IOException, MessagingException
    {
    	return executeSimpleCommand(command, false);
    }
    
    private List<String> executeSimpleCommand(String command, boolean sensitive)
    throws IOException, MessagingException
    {
        List<String> results = new ArrayList<String>();
        if (command != null)
        {
            writeLine(command);
            writeLine(command, sensitive);
        }

        boolean cont = false;
@@ -509,8 +526,8 @@ public class SmtpTransport extends Transport
        try
        {
            executeSimpleCommand("AUTH LOGIN");
            executeSimpleCommand(new String(Base64.encodeBase64(username.getBytes())));
            executeSimpleCommand(new String(Base64.encodeBase64(password.getBytes())));
            executeSimpleCommand(new String(Base64.encodeBase64(username.getBytes())), true);
            executeSimpleCommand(new String(Base64.encodeBase64(password.getBytes())), true);
        }
        catch (MessagingException me)
        {
@@ -530,7 +547,7 @@ public class SmtpTransport extends Transport
        data = new Base64().encode(data);
        try
        {
            executeSimpleCommand("AUTH PLAIN " + new String(data));
            executeSimpleCommand("AUTH PLAIN " + new String(data), true);
        }
        catch (MessagingException me)
        {
@@ -579,7 +596,7 @@ public class SmtpTransport extends Transport
        String b64CRAMString = new String(b64CRAM, "US-ASCII");
        try
        {
            executeSimpleCommand(b64CRAMString);
            executeSimpleCommand(b64CRAMString, true);
        }
        catch (MessagingException me)
        {