1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 03:32:22 -05:00

SMTP: fix 3024482, avoid duplicate messages with gmail

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1228 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-20 14:09:40 +00:00
parent 70b368a66b
commit 7064d5a690
2 changed files with 36 additions and 19 deletions

View File

@ -194,6 +194,7 @@ public abstract class ExchangeSession {
/** /**
* Return standard zulu date formatter. * Return standard zulu date formatter.
*
* @return zulu date formatter * @return zulu date formatter
*/ */
public static SimpleDateFormat getZuluDateFormat() { public static SimpleDateFormat getZuluDateFormat() {
@ -912,29 +913,35 @@ public abstract class ExchangeSession {
* Detect visible recipients in message body to determine bcc recipients * Detect visible recipients in message body to determine bcc recipients
* *
* @param rcptToRecipients recipients list * @param rcptToRecipients recipients list
* @param mimeMessage mime message * @param mimeMessage mime message
* @throws IOException on error * @throws IOException on error
* @throws MessagingException on error * @throws MessagingException on error
*/ */
public void sendMessage(List<String> rcptToRecipients, MimeMessage mimeMessage) throws IOException, MessagingException { public void sendMessage(List<String> rcptToRecipients, MimeMessage mimeMessage) throws IOException, MessagingException {
// Exchange 2007 : skip From: header // check Sent folder for duplicates
mimeMessage.removeHeader("from"); ExchangeSession.MessageList messages = searchMessages(SENT, headerEquals("message-id", mimeMessage.getMessageID()));
if (!messages.isEmpty()) {
LOGGER.debug("Dropping message: already sent");
} else {
// Exchange 2007 : skip From: header
mimeMessage.removeHeader("from");
// remove visible recipients from list // remove visible recipients from list
Set<String> visibleRecipients = new HashSet<String>(); Set<String> visibleRecipients = new HashSet<String>();
Address[] recipients = mimeMessage.getAllRecipients(); Address[] recipients = mimeMessage.getAllRecipients();
for (Address address : recipients) { for (Address address : recipients) {
visibleRecipients.add(address.toString()); visibleRecipients.add(address.toString());
}
for (String recipient : rcptToRecipients) {
if (!visibleRecipients.contains(recipient)) {
mimeMessage.addRecipient(javax.mail.Message.RecipientType.BCC, new InternetAddress(recipient));
} }
} for (String recipient : rcptToRecipients) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!visibleRecipients.contains(recipient)) {
mimeMessage.writeTo(baos); mimeMessage.addRecipient(javax.mail.Message.RecipientType.BCC, new InternetAddress(recipient));
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mimeMessage.writeTo(baos);
sendMessage(baos.toByteArray()); sendMessage(baos.toByteArray());
}
} }
/** /**
@ -2778,11 +2785,11 @@ public abstract class ExchangeSession {
properties.put("haspicture", "true"); properties.put("haspicture", "true");
} }
} }
LOGGER.debug("Create or update contact "+itemName+": "+properties); LOGGER.debug("Create or update contact " + itemName + ": " + properties);
// reset missing properties to null // reset missing properties to null
for (String key : CONTACT_ATTRIBUTES) { for (String key : CONTACT_ATTRIBUTES) {
if (!"imapUid".equals(key) && !"etag".equals(key) && !"urlcompname".equals(key) if (!"imapUid".equals(key) && !"etag".equals(key) && !"urlcompname".equals(key)
&& !"lastmodified".equals(key) && && !"lastmodified".equals(key) &&
!properties.containsKey(key)) { !properties.containsKey(key)) {
properties.put(key, null); properties.put(key, null);
} }

View File

@ -148,6 +148,16 @@ public class TestSmtp extends AbstractDavMailTestCase {
sendAndCheckMessage(mimeMessage); sendAndCheckMessage(mimeMessage);
} }
public void testSendMessageTwice() throws IOException, MessagingException, InterruptedException {
String body = "First line\r\n.\r\nSecond line";
MimeMessage mimeMessage = new MimeMessage((Session) null);
mimeMessage.addHeader("to", Settings.getProperty("davmail.to"));
mimeMessage.setSubject("Test subject");
mimeMessage.setText(body);
sendAndCheckMessage(mimeMessage);
sendAndCheckMessage(mimeMessage);
}
public void testQuit() throws IOException { public void testQuit() throws IOException {
writeLine("QUIT"); writeLine("QUIT");
assertEquals("221 Closing connection", readLine()); assertEquals("221 Closing connection", readLine());