mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22: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:
parent
70b368a66b
commit
7064d5a690
@ -194,6 +194,7 @@ public abstract class ExchangeSession {
|
||||
|
||||
/**
|
||||
* Return standard zulu date formatter.
|
||||
*
|
||||
* @return zulu date formatter
|
||||
*/
|
||||
public static SimpleDateFormat getZuluDateFormat() {
|
||||
@ -912,29 +913,35 @@ public abstract class ExchangeSession {
|
||||
* Detect visible recipients in message body to determine bcc recipients
|
||||
*
|
||||
* @param rcptToRecipients recipients list
|
||||
* @param mimeMessage mime message
|
||||
* @throws IOException on error
|
||||
* @param mimeMessage mime message
|
||||
* @throws IOException on error
|
||||
* @throws MessagingException on error
|
||||
*/
|
||||
public void sendMessage(List<String> rcptToRecipients, MimeMessage mimeMessage) throws IOException, MessagingException {
|
||||
// Exchange 2007 : skip From: header
|
||||
mimeMessage.removeHeader("from");
|
||||
// check Sent folder for duplicates
|
||||
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
|
||||
Set<String> visibleRecipients = new HashSet<String>();
|
||||
Address[] recipients = mimeMessage.getAllRecipients();
|
||||
for (Address address : recipients) {
|
||||
visibleRecipients.add(address.toString());
|
||||
}
|
||||
for (String recipient : rcptToRecipients) {
|
||||
if (!visibleRecipients.contains(recipient)) {
|
||||
mimeMessage.addRecipient(javax.mail.Message.RecipientType.BCC, new InternetAddress(recipient));
|
||||
// remove visible recipients from list
|
||||
Set<String> visibleRecipients = new HashSet<String>();
|
||||
Address[] recipients = mimeMessage.getAllRecipients();
|
||||
for (Address address : recipients) {
|
||||
visibleRecipients.add(address.toString());
|
||||
}
|
||||
}
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
mimeMessage.writeTo(baos);
|
||||
for (String recipient : rcptToRecipients) {
|
||||
if (!visibleRecipients.contains(recipient)) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
LOGGER.debug("Create or update contact "+itemName+": "+properties);
|
||||
LOGGER.debug("Create or update contact " + itemName + ": " + properties);
|
||||
// reset missing properties to null
|
||||
for (String key : CONTACT_ATTRIBUTES) {
|
||||
if (!"imapUid".equals(key) && !"etag".equals(key) && !"urlcompname".equals(key)
|
||||
&& !"lastmodified".equals(key) &&
|
||||
&& !"lastmodified".equals(key) &&
|
||||
!properties.containsKey(key)) {
|
||||
properties.put(key, null);
|
||||
}
|
||||
|
@ -148,6 +148,16 @@ public class TestSmtp extends AbstractDavMailTestCase {
|
||||
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 {
|
||||
writeLine("QUIT");
|
||||
assertEquals("221 Closing connection", readLine());
|
||||
|
Loading…
Reference in New Issue
Block a user