SMTP: fix 3489007, Sparrow AUTH PLAIN authentication support
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1916 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
ad94b01356
commit
67766c818f
|
@ -244,10 +244,15 @@ public class SmtpConnection extends AbstractConnection {
|
||||||
*/
|
*/
|
||||||
protected void decodeCredentials(String encodedCredentials) throws IOException {
|
protected void decodeCredentials(String encodedCredentials) throws IOException {
|
||||||
String decodedCredentials = base64Decode(encodedCredentials);
|
String decodedCredentials = base64Decode(encodedCredentials);
|
||||||
int index = decodedCredentials.indexOf((char) 0, 1);
|
int startIndex = decodedCredentials.indexOf((char) 0);
|
||||||
if (index > 0) {
|
if (startIndex >=0) {
|
||||||
userName = decodedCredentials.substring(1, index);
|
int endIndex = decodedCredentials.indexOf((char) 0, startIndex+1);
|
||||||
password = decodedCredentials.substring(index + 1);
|
if (endIndex >=0) {
|
||||||
|
userName = decodedCredentials.substring(startIndex+1, endIndex);
|
||||||
|
password = decodedCredentials.substring(endIndex + 1);
|
||||||
|
} else {
|
||||||
|
throw new DavMailException("EXCEPTION_INVALID_CREDENTIALS");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new DavMailException("EXCEPTION_INVALID_CREDENTIALS");
|
throw new DavMailException("EXCEPTION_INVALID_CREDENTIALS");
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,7 @@ import org.apache.commons.codec.binary.Base64;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.Session;
|
import javax.mail.Session;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.*;
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +91,8 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||||
|
|
||||||
String banner = readLine();
|
String banner = readLine();
|
||||||
assertNotNull(banner);
|
assertNotNull(banner);
|
||||||
String credentials = (char) 0 + Settings.getProperty("davmail.username") + (char) 0 + Settings.getProperty("davmail.password");
|
//String credentials = (char) 0 + Settings.getProperty("davmail.username") + (char) 0 + Settings.getProperty("davmail.password");
|
||||||
|
String credentials = Settings.getProperty("davmail.username") + (char) 0 + Settings.getProperty("davmail.username") + (char) 0 + Settings.getProperty("davmail.password");
|
||||||
writeLine("AUTH PLAIN " + new String(new Base64().encode(credentials.getBytes())));
|
writeLine("AUTH PLAIN " + new String(new Base64().encode(credentials.getBytes())));
|
||||||
assertEquals("235 OK Authenticated", readLine());
|
assertEquals("235 OK Authenticated", readLine());
|
||||||
}
|
}
|
||||||
|
@ -112,8 +110,11 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAndCheckMessage(MimeMessage mimeMessage, String from, String bcc) throws IOException, MessagingException, InterruptedException {
|
public void sendAndCheckMessage(MimeMessage mimeMessage, String from, String bcc) throws IOException, MessagingException, InterruptedException {
|
||||||
|
// generate message id
|
||||||
|
mimeMessage.saveChanges();
|
||||||
|
// mimeMessage.writeTo(System.out);
|
||||||
|
|
||||||
// copy Message-id to references header
|
// copy Message-id to references header
|
||||||
mimeMessage.writeTo(System.out);
|
|
||||||
mimeMessage.addHeader("references", mimeMessage.getHeader("message-id")[0]);
|
mimeMessage.addHeader("references", mimeMessage.getHeader("message-id")[0]);
|
||||||
if (from != null) {
|
if (from != null) {
|
||||||
writeLine("MAIL FROM:" + from);
|
writeLine("MAIL FROM:" + from);
|
||||||
|
@ -238,4 +239,16 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||||
assertEquals("221 Closing connection", readLine());
|
assertEquals("221 Closing connection", readLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testBrokenMessage() throws MessagingException, IOException, InterruptedException {
|
||||||
|
MimeMessage mimeMessage = new MimeMessage(null, new FileInputStream("test.eml"));
|
||||||
|
sendAndCheckMessage(mimeMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testBrokenMessage2() throws MessagingException, IOException, InterruptedException {
|
||||||
|
MimeMessage mimeMessage = new MimeMessage(null, new org.apache.commons.codec.binary.Base64InputStream(new FileInputStream("broken64.txt")));
|
||||||
|
mimeMessage.addHeader("To", Settings.getProperty("davmail.to"));
|
||||||
|
sendAndCheckMessage(mimeMessage);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue