use of javax.mail.internet.MailDateFormat in project zm-mailbox by Zimbra.
the class ImapAppender method appendSlow.
// Slow APPEND for servers lacking UIDPLUS capability
private long appendSlow(MessageInfo mi, Literal lit) throws IOException, MessagingException {
MailboxInfo mb = connection.getMailboxInfo();
if (mdf == null) {
mdf = new MailDateFormat();
}
if (mb == null || !mailbox.equals(mb.getName())) {
connection.select(mailbox);
}
long startUid = getUidNext();
connection.append(mailbox, mi.flags, mi.date, lit);
if (mi.mm.getSentDate() == null || mi.mm.getMessageID() == null) {
// "Date" and "Message-ID" headers are required to find message
return -1;
}
// Check new messages for the one we just appended
try {
// exchange doesn't give accurate UIDNEXT unless mbox is selected again.
connection.select(mailbox);
long endUid = getUidNext() - 1;
if (startUid <= endUid) {
List<Long> found = findUids(startUid + ":" + endUid, mi);
if (found.size() == 1) {
return found.get(0);
}
}
// If not found then server must have de-duped the message. This
// is certainly possible with GMail. Search through the entire mailbox
// for matching message and hope this is not too slow.
List<Long> uids;
try {
// bug 45385: Temporarily increase timeout to 10 minutes in case of slow search.
// Not pretty, but hopefully we never get here since most servers now support
// UIDPLUS or don't de-dup messages.
// bug 64062 : let's try 2 minutes. hopefully search shouldn't take too long now that we use msg id rather than subject
connection.setReadTimeout(2 * 60);
uids = connection.uidSearch(getSearchParams(mi));
} finally {
connection.setReadTimeout(connection.getConfig().getReadTimeout());
}
Iterator<Long> it = uids.iterator();
while (it.hasNext()) {
List<Long> found = findUids(nextSeq(it, 5), mi);
if (found.size() > 0) {
if (found.size() > 1) {
ZimbraLog.imap_client.warn("found more than one (%d)" + "matching UID during appendSlow. Probably a leftover dupe from earlier bugs?", found.size());
if (ZimbraLog.imap_client.isDebugEnabled()) {
ZimbraLog.imap_client.debug("potential duplicate ids = %s", Joiner.on(',').join(found));
}
}
return found.get(0);
}
}
} catch (Exception e) {
// if this is a real exception (e.g. network went down) next command will fail regardless.
// otherwise, don't allow appendSlow to create loop
ZimbraLog.imap_client.warn("Dedupe search in appendSlow failed.", e);
}
// this usually is OK, and actually the way Exchange has been working due to size check in matches()
// we delete the local tracker and allow next sync to get the current version of message
ZimbraLog.imap_client.warn("append slow failed to find appended message id");
// If still not found, then give up :(
return -1;
}
use of javax.mail.internet.MailDateFormat in project zm-mailbox by Zimbra.
the class LmtpHandler method getAdditionalHeaders.
/*
* Generates the <tt>Return-Path</tt> and <tt>Received</tt> headers
* for the current incoming message.
*/
protected String getAdditionalHeaders() {
StringBuilder headers = new StringBuilder();
// Assemble Return-Path header
String sender = "";
if (mEnvelope.hasSender()) {
sender = mEnvelope.getSender().getEmailAddress();
}
headers.append(String.format("Return-Path: <%s>\r\n", sender));
// Assemble Received header
String localHostname = "unknown";
try {
localHostname = Provisioning.getInstance().getLocalServer().getName();
} catch (ServiceException e) {
ZimbraLog.lmtp.warn("Unable to determine local hostname", e);
}
String timestamp = new MailDateFormat().format(new Date());
String name = "Received: ";
String value = String.format("from %s (LHLO %s) (%s) by %s with LMTP; %s", mRemoteHostname, mLhloArg, mRemoteAddress, localHostname, timestamp);
headers.append(name);
headers.append(MimeUtility.fold(name.length(), value));
headers.append("\r\n");
return headers.toString();
}
use of javax.mail.internet.MailDateFormat in project zm-mailbox by Zimbra.
the class TestPop3Import method testBogusDate.
/**
* Tests import of a message with a date in the future (bug 17031).
*/
@Test
public void testBogusDate() throws Exception {
// Create remote account
prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
// Add message with bogus date to remote mailbox
MailDateFormat format = new MailDateFormat();
Date date = format.parse("Thu, 31 Aug 2039 10:29:46 +0800");
String message = TestUtil.getTestMessage(NAME_PREFIX + " testBogusDate", null, null, date);
ZMailbox remoteMbox = TestUtil.getZMailbox(TEMP_USER_NAME);
String folderId = Integer.toString(Mailbox.ID_FOLDER_INBOX);
remoteMbox.addMessage(folderId, null, null, 0, message, true);
// Update the data source, import data
ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
ZPop3DataSource ds = getZDataSource();
ds.setUsername(TEMP_USER_NAME);
ds.setEnabled(true);
localMbox.modifyDataSource(ds);
// Import data and make sure the message was imported
List<ZMessage> messages = TestUtil.search(localMbox, "in:inbox " + NAME_PREFIX);
Assert.assertEquals("Found unexpected message in local inbox", 0, messages.size());
TestUtil.importDataSource(ds, localMbox, remoteMbox);
messages = TestUtil.search(localMbox, "in:inbox " + NAME_PREFIX);
Assert.assertEquals("Imported message not found", 1, messages.size());
}
Aggregations