From a4eef56122fa353e11926b2d57fd4b87ac54e9a7 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Fri, 25 Aug 2006 16:43:07 +0000 Subject: [PATCH] fix 332626 transfer date of original message when appending message to imap folder, original patch by mhovis, with some reworking by me, sr=mscott --- mailnews/imap/public/nsIImapMessageSink.idl | 4 +-- mailnews/imap/src/nsImapMailFolder.cpp | 5 +++- mailnews/imap/src/nsImapProtocol.cpp | 32 +++++++++++++++++++-- mailnews/imap/src/nsImapProtocol.h | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mailnews/imap/public/nsIImapMessageSink.idl b/mailnews/imap/public/nsIImapMessageSink.idl index 9fe26186faa..0cd550b7938 100644 --- a/mailnews/imap/public/nsIImapMessageSink.idl +++ b/mailnews/imap/public/nsIImapMessageSink.idl @@ -42,7 +42,7 @@ interface nsIFileSpec; interface nsIMsgMailNewsUrl; -[scriptable, uuid(5a53b814-68b1-11d3-a53e-0060b0fc04b7)] +[scriptable, uuid(71EDC407-FF4B-4D70-BE35-4001E992D8E7)] interface nsIImapMessageSink : nsISupports { // set up messge download output stream @@ -73,5 +73,5 @@ interface nsIImapMessageSink : nsISupports { void SetContentModified(in nsIImapUrl aImapUrl, in nsImapContentModifiedType modified); void SetImageCacheSessionForUrl(in nsIMsgMailNewsUrl aMailUrl); - unsigned long getCurMoveCopyMessageFlags(in nsIImapUrl runningUrl); + unsigned long getCurMoveCopyMessageInfo(in nsIImapUrl runningUrl, out PRTime date); }; diff --git a/mailnews/imap/src/nsImapMailFolder.cpp b/mailnews/imap/src/nsImapMailFolder.cpp index 44b1a89539a..fec2628af0e 100644 --- a/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mailnews/imap/src/nsImapMailFolder.cpp @@ -115,6 +115,7 @@ #include "nsMsgCompCID.h" #include "nsICacheEntryDescriptor.h" + static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); static NS_DEFINE_CID(kCImapDB, NS_IMAPDB_CID); @@ -4722,7 +4723,7 @@ nsImapMailFolder::SetImageCacheSessionForUrl(nsIMsgMailNewsUrl *mailurl) return rv; } -NS_IMETHODIMP nsImapMailFolder::GetCurMoveCopyMessageFlags(nsIImapUrl *runningUrl, PRUint32 *aResult) +NS_IMETHODIMP nsImapMailFolder::GetCurMoveCopyMessageInfo(nsIImapUrl *runningUrl, PRTime *aDate, PRUint32 *aResult) { nsCOMPtr copyState; runningUrl->GetCopyState(getter_AddRefs(copyState)); @@ -4736,6 +4737,8 @@ NS_IMETHODIMP nsImapMailFolder::GetCurMoveCopyMessageFlags(nsIImapUrl *runningUr mailCopyState->m_message->GetLabel(&label); if (label != 0) *aResult |= label << 25; + if (aDate) + mailCopyState->m_message->GetDate(aDate); } // if we don't have a source header, and it's not the drafts folder, // then mark the message read, since it must be an append to the diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index 03b8440892c..ed2440b05e0 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -5360,8 +5360,9 @@ void nsImapProtocol::OnAppendMsgFromFile() { imapMessageFlagsType flagsToSet = 0; PRUint32 msgFlags = 0; + PRTime date = 0; if (m_imapMessageSink) - m_imapMessageSink->GetCurMoveCopyMessageFlags(m_runningUrl, &msgFlags); + m_imapMessageSink->GetCurMoveCopyMessageInfo(m_runningUrl, &date, &msgFlags); if (msgFlags & MSG_FLAG_READ) flagsToSet |= kImapMsgSeenFlag; @@ -5370,7 +5371,7 @@ void nsImapProtocol::OnAppendMsgFromFile() // convert msg flag label (0xE000000) to imap flag label (0x0E00) if (msgFlags & MSG_FLAG_LABELS) flagsToSet |= (msgFlags & MSG_FLAG_LABELS) >> 16; - UploadMessageFromFile(fileSpec, mailboxName, flagsToSet); + UploadMessageFromFile(fileSpec, mailboxName, date, flagsToSet); PR_Free( mailboxName ); } else @@ -5382,6 +5383,7 @@ void nsImapProtocol::OnAppendMsgFromFile() void nsImapProtocol::UploadMessageFromFile (nsIFileSpec* fileSpec, const char* mailboxName, + PRTime date, imapMessageFlagsType flags) { if (!fileSpec || !mailboxName) return; @@ -5415,6 +5417,32 @@ void nsImapProtocol::UploadMessageFromFile (nsIFileSpec* fileSpec, command.Append(flagString); command.Append(")"); } + + // date should never be 0, but just in case... + if (date) + { + /* Use PR_FormatTimeUSEnglish() to format the date in US English format, + then figure out what our local GMT offset is, and append it (since + PR_FormatTimeUSEnglish() can't do that.) Generate four digit years as + per RFC 1123 (superceding RFC 822.) + */ + char szDateTime[64]; + char dateStr[100]; + PRExplodedTime exploded; + PR_ExplodeTime(date, PR_LocalTimeParameters, &exploded); + PR_FormatTimeUSEnglish(szDateTime, sizeof(szDateTime), "%d-%b-%Y %H:%M:%S", &exploded); + PRExplodedTime now; + PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now); + int gmtoffset = (now.tm_params.tp_gmt_offset + now.tm_params.tp_dst_offset) / 60; + PR_snprintf(dateStr, sizeof(dateStr), + " \"%s %c%02d%02d\"", + szDateTime, + (gmtoffset >= 0 ? '+' : '-'), + ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) / 60), + ((gmtoffset >= 0 ? gmtoffset : -gmtoffset) % 60)); + + command.Append(dateStr); + } command.Append(" {"); dataBuffer = (char*) PR_CALLOC(COPY_BUFFER_SIZE+1); diff --git a/mailnews/imap/src/nsImapProtocol.h b/mailnews/imap/src/nsImapProtocol.h index 84a3490369c..990b0c9c7d2 100644 --- a/mailnews/imap/src/nsImapProtocol.h +++ b/mailnews/imap/src/nsImapProtocol.h @@ -407,7 +407,7 @@ private: void WaitForPotentialListOfMsgsToFetch(PRUint32 **msgIdList, PRUint32 &msgCount); void WaitForPotentialListOfBodysToFetch(PRUint32 **msgIdList, PRUint32 &msgCount); void HeaderFetchCompleted(); - void UploadMessageFromFile(nsIFileSpec* fileSpec, const char* mailboxName, + void UploadMessageFromFile(nsIFileSpec* fileSpec, const char* mailboxName, PRTime date, imapMessageFlagsType flags); // mailbox name utilities.