mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
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 {
|
||||
String decodedCredentials = base64Decode(encodedCredentials);
|
||||
int index = decodedCredentials.indexOf((char) 0, 1);
|
||||
if (index > 0) {
|
||||
userName = decodedCredentials.substring(1, index);
|
||||
password = decodedCredentials.substring(index + 1);
|
||||
int startIndex = decodedCredentials.indexOf((char) 0);
|
||||
if (startIndex >=0) {
|
||||
int endIndex = decodedCredentials.indexOf((char) 0, startIndex+1);
|
||||
if (endIndex >=0) {
|
||||
userName = decodedCredentials.substring(startIndex+1, endIndex);
|
||||
password = decodedCredentials.substring(endIndex + 1);
|
||||
} else {
|
||||
throw new DavMailException("EXCEPTION_INVALID_CREDENTIALS");
|
||||
}
|
||||
} else {
|
||||
throw new DavMailException("EXCEPTION_INVALID_CREDENTIALS");
|
||||
}
|
||||
|
@ -29,10 +29,7 @@ import org.apache.commons.codec.binary.Base64;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
@ -94,7 +91,8 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||
|
||||
String banner = readLine();
|
||||
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())));
|
||||
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 {
|
||||
// generate message id
|
||||
mimeMessage.saveChanges();
|
||||
// mimeMessage.writeTo(System.out);
|
||||
|
||||
// copy Message-id to references header
|
||||
mimeMessage.writeTo(System.out);
|
||||
mimeMessage.addHeader("references", mimeMessage.getHeader("message-id")[0]);
|
||||
if (from != null) {
|
||||
writeLine("MAIL FROM:" + from);
|
||||
@ -238,4 +239,16 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||
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…
x
Reference in New Issue
Block a user