more on uber copy service - enable move/copy messages from news to pop3 & imap4, from imap4 to imap4, from imap4 to pop3

This commit is contained in:
jefft%netscape.com 1999-07-18 22:33:25 +00:00
Родитель bbf5b0dba3
Коммит 5f5eabc97c
24 изменённых файлов: 514 добавлений и 201 удалений

Просмотреть файл

@ -58,13 +58,13 @@ public:
NS_IMETHOD SetCopyResponseUid(nsIImapProtocol* aProtocol,
nsMsgKeyArray* keyArray,
const char *msgIdString,
void* copyState) = 0;
nsISupports* copyState) = 0;
NS_IMETHOD SetAppendMsgUid(nsIImapProtocol* aProtocol,
nsMsgKey newKey,
void* copyState) = 0;
nsISupports* copyState) = 0;
NS_IMETHOD GetMessageId(nsIImapProtocol* aProtocol,
nsString2* messageId,
void* copyState) = 0;
nsISupports* copyState) = 0;
};
#endif

Просмотреть файл

@ -83,7 +83,7 @@ public:
NS_IMETHOD LoadNextQueuedUrl(nsIImapProtocol* aProtocol,
nsIImapIncomingServer *incomingServer) = 0;
NS_IMETHOD CopyNextStreamMessage(nsIImapProtocol* aProtocol,
void* copyState) = 0;
nsISupports* copyState) = 0;
};

Просмотреть файл

@ -88,7 +88,9 @@ public:
NS_IMETHOD GetSupportedUserFlags(PRUint16 *flags) = 0;
// this is for the temp message display hack
NS_IMETHOD GetDisplayStream (nsIWebShell **webShell) = 0;
// ** jt - let's try it a litter more generic way
NS_IMETHOD GetStreamConsumer (nsISupports **aSupport) = 0;
NS_IMETHOD GetRunningUrl(nsIURI **aUrl) = 0;
// Tell thread to die
NS_IMETHOD TellThreadToDie(PRBool isSafeToDie) = 0;

Просмотреть файл

@ -141,7 +141,7 @@ public:
PRBool isMove,
nsIUrlListener* aUrlListener,
nsIURI** aURL,
void* copyState) = 0;
nsISupports* copyState) = 0;
NS_IMETHOD AppendMessageFromFile(nsIEventQueue* aClientEventQ,
nsIFileSpec* aFileSpec,
nsIMsgFolder* aDstFolder,
@ -150,7 +150,7 @@ public:
PRBool inSelectedState, // needs to be in
nsIUrlListener* aUrlListener,
nsIURI** aURL,
void* copyState) = 0;
nsISupports* copyState) = 0;
};

Просмотреть файл

@ -172,8 +172,8 @@ public:
NS_IMETHOD SetAllowContentChange(PRBool allowContentChange) = 0;
NS_IMETHOD GetAllowContentChange(PRBool *results) = 0;
NS_IMETHOD SetCopyState(void* copyState) = 0;
NS_IMETHOD GetCopyState(void** copyState) = 0;
NS_IMETHOD SetCopyState(nsISupports* copyState) = 0;
NS_IMETHOD GetCopyState(nsISupports** copyState) = 0;
NS_IMETHOD SetMsgFileSpec(nsIFileSpec* aFileSpec) = 0;
NS_IMETHOD GetMsgFileSpec(nsIFileSpec** aFileSpec) = 0;

Просмотреть файл

@ -248,7 +248,7 @@ nsImapIncomingServer::GetImapConnectionAndLoadUrl(nsIEventQueue*
if (aURL)
{
*aURL = mailnewsurl;
NS_IF_RELEASE(*aURL);
NS_IF_ADDREF(*aURL);
}
return rv;

Просмотреть файл

@ -89,7 +89,6 @@ nsImapMailFolder::nsImapMailFolder() :
m_urlRunning(PR_FALSE), m_tempMessageFile(MESSAGE_PATH)
{
m_pathName = nsnull;
m_copyState = nsnull;
m_appendMsgMonitor = PR_NewMonitor();
nsresult rv;
@ -1008,6 +1007,7 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages,
if (NS_FAILED(rv)) return rv;
rv = InitCopyState(srcSupport, messages, PR_TRUE, PR_TRUE, nsnull);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupports> copySupport = do_QueryInterface(m_copyState);
m_copyState->m_curIndex = m_copyState->m_totalCount;
NS_WITH_SERVICE(nsIImapService, imapService, kCImapService, &rv);
if (NS_SUCCEEDED(rv) && imapService)
@ -1015,7 +1015,7 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages,
this, messageIds.GetBuffer(),
trashFolder, PR_TRUE, PR_TRUE,
this, nsnull,
(void*)m_copyState);
copySupport);
if (NS_SUCCEEDED(rv))
{
nsImapMoveCopyMsgTxn* undoMsgTxn = new nsImapMoveCopyMsgTxn(
@ -1626,12 +1626,15 @@ NS_IMETHODIMP nsImapMailFolder::EndCopy(PRBool copySucceeded)
if (NS_FAILED(rv)) return rv;
rv = QueryInterface(nsIUrlListener::GetIID(),
getter_AddRefs(urlListener));
nsCOMPtr<nsISupports> copySupport;
if (m_copyState)
copySupport = do_QueryInterface(m_copyState);
rv = imapService->AppendMessageFromFile(m_eventQueue,
m_copyState->m_tmpFileSpec,
this, "", PR_TRUE,
m_copyState->m_selectedState,
urlListener, nsnull,
(void*) m_copyState);
copySupport);
}
return rv;
}
@ -2167,19 +2170,50 @@ nsImapMailFolder::NormalEndMsgWriteStream(nsIImapProtocol* aProtocol)
nsresult res = NS_OK;
if (m_tempMessageStream)
{
nsCOMPtr<nsIWebShell> webShell;
nsCOMPtr<nsISupports> aSupport;
m_tempMessageStream->Close();
res = aProtocol->GetDisplayStream(getter_AddRefs(webShell));
if (NS_SUCCEEDED(res) && webShell)
{
nsFilePath filePath(MESSAGE_PATH);
nsFileURL fileURL(filePath);
char * message_path_url = PL_strdup(fileURL.GetAsString());
res = aProtocol->GetStreamConsumer(getter_AddRefs(aSupport));
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIWebShell> webShell;
nsFilePath filePath(MESSAGE_PATH);
res = webShell->LoadURL(nsAutoString(message_path_url).GetUnicode(), nsnull, PR_TRUE, nsURLReloadBypassCache, 0);
PR_FREEIF(message_path_url);
}
webShell = do_QueryInterface(aSupport, &res);
if (NS_SUCCEEDED(res) && webShell)
{
nsFileURL fileURL(filePath);
char * message_path_url = PL_strdup(fileURL.GetAsString());
res = webShell->LoadURL(nsAutoString(message_path_url).GetUnicode(), nsnull, PR_TRUE, nsURLReloadBypassCache, 0);
PR_FREEIF(message_path_url);
}
else
{
nsCOMPtr<nsIStreamListener> streamListener;
streamListener = do_QueryInterface(aSupport, &res);
if (NS_SUCCEEDED(res) && streamListener)
{
nsCOMPtr<nsIURI> aUrl;
res = aProtocol->GetRunningUrl(getter_AddRefs(aUrl));
nsFileSpec fileSpec(filePath);
nsInputFileStream *inputFileStream = nsnull;
nsCOMPtr<nsIInputStream> inputStream;
inputFileStream = new nsInputFileStream(fileSpec);
if (!inputFileStream) return NS_ERROR_OUT_OF_MEMORY;
inputStream =
do_QueryInterface(inputFileStream->GetIStream(), &res);
PRUint32 fileSize = 0;
res = inputStream->GetLength(&fileSize);
streamListener->OnStartRequest(aUrl, "");
streamListener->OnDataAvailable(aUrl, inputStream,
fileSize);
streamListener->OnStopRequest(aUrl, 0, nsnull);
inputStream = null_nsCOMPtr();
delete inputFileStream;
}
}
}
}
return res;
@ -2554,15 +2588,18 @@ NS_IMETHODIMP
nsImapMailFolder::SetCopyResponseUid(nsIImapProtocol* aProtocol,
nsMsgKeyArray* aKeyArray,
const char* msgIdString,
void* copyState)
nsISupports* copyState)
{ // CopyMessages() only
nsresult rv = NS_OK;
nsCOMPtr<nsImapMoveCopyMsgTxn> msgTxn;
if (copyState)
{
nsImapMailCopyState* mailCopyState = (nsImapMailCopyState*) copyState;
msgTxn = do_QueryInterface(mailCopyState->m_undoMsgTxn, &rv);
nsCOMPtr<nsImapMailCopyState> mailCopyState =
do_QueryInterface(copyState, &rv);
if (NS_FAILED(rv)) return rv;
if (mailCopyState->m_undoMsgTxn)
msgTxn = do_QueryInterface(mailCopyState->m_undoMsgTxn, &rv);
}
if (msgTxn)
msgTxn->SetCopyResponseUid(aKeyArray, msgIdString);
@ -2573,12 +2610,14 @@ nsImapMailFolder::SetCopyResponseUid(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapMailFolder::SetAppendMsgUid(nsIImapProtocol* aProtocol,
nsMsgKey aKey,
void* copyState)
nsISupports* copyState)
{
nsresult rv = NS_OK;
if (copyState)
{
nsImapMailCopyState* mailCopyState = (nsImapMailCopyState*) copyState;
nsCOMPtr<nsImapMailCopyState> mailCopyState =
do_QueryInterface(copyState, &rv);
if (NS_FAILED(rv)) return rv;
if (mailCopyState->m_undoMsgTxn) // CopyMessages()
{
nsImapMailCopyState* mailCopyState =
@ -2598,12 +2637,14 @@ nsImapMailFolder::SetAppendMsgUid(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapMailFolder::GetMessageId(nsIImapProtocol* aProtocl,
nsString2* messageId,
void* copyState)
nsISupports* copyState)
{
nsresult rv = NS_OK;
if (copyState)
{
nsImapMailCopyState* mailCopyState = (nsImapMailCopyState*) copyState;
nsCOMPtr<nsImapMailCopyState> mailCopyState =
do_QueryInterface(copyState, &rv);
if (NS_FAILED(rv)) return rv;
if (mailCopyState->m_listener)
rv = mailCopyState->m_listener->GetMessageId(messageId);
}
@ -2773,11 +2814,15 @@ nsImapMailFolder::LoadNextQueuedUrl(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapMailFolder::CopyNextStreamMessage(nsIImapProtocol* aProtocol,
void* copyState)
nsISupports* copyState)
{
nsresult rv = NS_ERROR_NULL_POINTER;
if (!copyState) return rv;
nsImapMailCopyState* mailCopyState = (nsImapMailCopyState*) copyState;
nsCOMPtr<nsImapMailCopyState> mailCopyState = do_QueryInterface(copyState,
&rv);
if (NS_FAILED(rv)) return rv;
if (!mailCopyState->m_streamCopy) return NS_OK;
if (mailCopyState->m_curIndex < mailCopyState->m_totalCount)
{
nsCOMPtr<nsISupports> aSupport =
@ -2791,6 +2836,16 @@ nsImapMailFolder::CopyNextStreamMessage(nsIImapProtocol* aProtocol,
this, mailCopyState->m_isMove);
}
}
else if (mailCopyState->m_isMove)
{
nsCOMPtr<nsIMsgFolder> srcFolder =
do_QueryInterface(mailCopyState->m_srcSupport, &rv);
if (NS_SUCCEEDED(rv) && srcFolder)
{
srcFolder->DeleteMessages(mailCopyState->m_messages, nsnull,
PR_FALSE);
}
}
return rv;
}
@ -2846,6 +2901,7 @@ nsImapMailFolder::CopyMessages2(nsIMsgFolder* srcFolder,
rv = InitCopyState(aSupport, messages, isMove, PR_TRUE, listener);
if(NS_FAILED(rv)) return rv;
m_copyState->m_streamCopy = PR_TRUE;
// ** jt - needs to create server to server move/copy undo msg txn
nsCOMPtr<nsISupports> msgSupport;
@ -2882,6 +2938,7 @@ nsImapMailFolder::CopyMessages(nsIMsgFolder* srcFolder,
nsMsgKeyArray srcKeyArray;
nsCOMPtr<nsIUrlListener> urlListener;
nsCOMPtr<nsISupports> srcSupport;
nsCOMPtr<nsISupports> copySupport;
SetTransactionManager(txnMgr);
@ -2923,12 +2980,13 @@ nsImapMailFolder::CopyMessages(nsIMsgFolder* srcFolder,
m_copyState->m_curIndex = m_copyState->m_totalCount;
copySupport = do_QueryInterface(m_copyState);
if (imapService)
rv = imapService->OnlineMessageCopy(m_eventQueue,
srcFolder, messageIds.GetBuffer(),
this, PR_TRUE, isMove,
urlListener, nsnull,
(void*)m_copyState);
copySupport);
if (NS_SUCCEEDED(rv))
{
nsImapMoveCopyMsgTxn* undoMsgTxn = new nsImapMoveCopyMsgTxn(
@ -2993,12 +3051,15 @@ nsImapMailFolder::CopyFileMessage(nsIFileSpec* fileSpec,
rv = InitCopyState(srcSupport, messages, PR_FALSE, isDraftOrTemplate,
listener);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISupports> copySupport;
if( m_copyState )
copySupport = do_QueryInterface(m_copyState);
rv = imapService->AppendMessageFromFile(m_eventQueue, fileSpec, this,
messageId.GetBuffer(),
PR_TRUE, isDraftOrTemplate,
urlListener, nsnull,
(void*) m_copyState);
copySupport);
return rv;
}
@ -3053,9 +3114,10 @@ nsImapMailFolder::CopyStreamMessage(nsIMessage* message,
}
nsImapMailCopyState::nsImapMailCopyState() : m_msgService(nsnull),
m_isMove(PR_FALSE), m_selectedState(PR_FALSE), m_curIndex(0), m_totalCount(0),
m_dataBuffer(nsnull)
m_isMove(PR_FALSE), m_selectedState(PR_FALSE), m_curIndex(0),
m_totalCount(0), m_streamCopy(PR_FALSE), m_dataBuffer(nsnull)
{
NS_INIT_REFCNT();
}
nsImapMailCopyState::~nsImapMailCopyState()
@ -3084,6 +3146,8 @@ nsImapMailCopyState::~nsImapMailCopyState()
}
}
NS_IMPL_ISUPPORTS(nsImapMailCopyState, NS_IMAPMAILCOPYSTATE_IID);
nsresult
nsImapMailFolder::InitCopyState(nsISupports* srcSupport,
nsISupportsArray* messages,
@ -3094,9 +3158,11 @@ nsImapMailFolder::InitCopyState(nsISupports* srcSupport,
nsresult rv = NS_ERROR_NULL_POINTER;
if (!srcSupport || !messages) return rv;
if (m_copyState) return NS_ERROR_FAILURE;
m_copyState = new nsImapMailCopyState();
nsImapMailCopyState* copyState = new nsImapMailCopyState();
m_copyState = do_QueryInterface(copyState);
if (!m_copyState) return NS_ERROR_OUT_OF_MEMORY;
if (srcSupport)
@ -3128,7 +3194,6 @@ nsImapMailFolder::ClearCopyState(nsresult rv)
if (NS_SUCCEEDED(result))
copyService->NotifyCompletion(m_copyState->m_srcSupport, this, rv);
delete m_copyState;
m_copyState = nsnull;
m_copyState = null_nsCOMPtr();
}
}

Просмотреть файл

@ -45,8 +45,23 @@ class nsImapMoveCoalescer;
#define FOUR_K 4096
struct nsImapMailCopyState
/* b64534f0-3d53-11d3-ac2a-00805f8ac968 */
#define NS_IMAPMAILCOPYSTATE_IID \
{ 0xb64534f0, 0x3d53, 0x11d3, \
{ 0xac, 0x2a, 0x00, 0x80, 0x5f, 0x8a, 0xc9, 0x68 } }
class nsImapMailCopyState: public nsISupports
{
public:
static const nsIID& GetIID()
{
static nsIID iid = NS_IMAPMAILCOPYSTATE_IID;
return iid;
}
NS_DECL_ISUPPORTS
nsImapMailCopyState();
virtual ~nsImapMailCopyState();
@ -62,6 +77,7 @@ struct nsImapMailCopyState
// be Nntp, Mailbox, or Imap
PRBool m_isMove; // is a move
PRBool m_selectedState; // needs to be in selected state; append msg
PRBool m_streamCopy;
PRUint32 m_curIndex; // message index to the message array which we are
// copying
PRUint32 m_totalCount;// total count of messages we have to do
@ -237,13 +253,13 @@ public:
NS_IMETHOD SetCopyResponseUid(nsIImapProtocol* aProtocol,
nsMsgKeyArray* keyArray,
const char* msgIdString,
void* copyState);
nsISupports* copyState);
NS_IMETHOD SetAppendMsgUid(nsIImapProtocol* aProtocol,
nsMsgKey aKey,
void* copyState);
nsISupports* copyState);
NS_IMETHOD GetMessageId(nsIImapProtocol* aProtocol,
nsString2* messageId,
void* copyState);
nsISupports* copyState);
// nsIImapMiscellaneousSink methods
NS_IMETHOD AddSearchResult(nsIImapProtocol* aProtocol,
@ -288,7 +304,7 @@ public:
NS_IMETHOD LoadNextQueuedUrl(nsIImapProtocol* aProtocol,
nsIImapIncomingServer *aInfo);
NS_IMETHOD CopyNextStreamMessage(nsIImapProtocol* aProtocol,
void* copyState);
nsISupports* copyState);
#ifdef DOING_FILTERS
// nsIMsgFilterHitNotification method(s)
@ -367,7 +383,7 @@ protected:
// *** jt - undo move/copy trasaction support
nsCOMPtr<nsITransactionManager> m_transactionManager;
nsCOMPtr<nsMsgTxn> m_pendingUndoTxn;
nsImapMailCopyState* m_copyState;
nsCOMPtr<nsImapMailCopyState> m_copyState;
PRMonitor *m_appendMsgMonitor;
};

Просмотреть файл

@ -451,7 +451,7 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
if (aURL)
{
rv = aURL->QueryInterface(nsIImapUrl::GetIID(),
(void **)&m_runningUrl);
getter_AddRefs(m_runningUrl));
if (NS_FAILED(rv)) return rv;
if (!m_server)
@ -552,7 +552,7 @@ void nsImapProtocol::ImapThreadMain(void *aParm)
me->m_inputStream = null_nsCOMPtr();
me->m_outputStream = null_nsCOMPtr();
me->m_outputConsumer = null_nsCOMPtr();
me->m_displayConsumer = null_nsCOMPtr();
me->m_streamConsumer = null_nsCOMPtr();
me->m_sinkEventQueue = null_nsCOMPtr();
me->m_eventQueue = null_nsCOMPtr();
me->m_server = null_nsCOMPtr();
@ -858,7 +858,8 @@ void nsImapProtocol::ProcessCurrentURL()
{
FindMailboxesIfNecessary();
nsIImapUrl::nsImapState imapState;
m_runningUrl->GetRequiredImapState(&imapState);
if (m_runningUrl)
m_runningUrl->GetRequiredImapState(&imapState);
if (imapState == nsIImapUrl::nsImapAuthenticatedState)
ProcessAuthenticatedStateURL();
else // must be a url that requires us to be in the selected stae
@ -883,15 +884,21 @@ void nsImapProtocol::ProcessCurrentURL()
HandleCurrentUrlError();
nsresult rv = NS_OK;
nsCOMPtr<nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(m_runningUrl, &rv);
if (NS_SUCCEEDED(rv) && mailnewsurl)
mailnewsurl->SetUrlState(PR_FALSE, NS_OK); // we are done with this url.
m_lastActiveTime = PR_Now(); // ** jt -- is this the best place for time stamp
PseudoInterrupt(FALSE); // clear this, because we must be done interrupting?
void *copyState = nsnull;
rv = m_runningUrl->GetCopyState(&copyState);
nsCOMPtr<nsISupports> copyState;
if (m_runningUrl)
rv = m_runningUrl->GetCopyState(getter_AddRefs(copyState));
if (NS_SUCCEEDED(rv) && m_imapMiscellaneousSink && copyState)
{
m_imapMiscellaneousSink->CopyNextStreamMessage(this, copyState);
WaitForFEEventCompletion();
}
// release this by hand so that we can load the next queued url without thinking
// this connection is busy running a url.
@ -980,17 +987,27 @@ NS_IMETHODIMP nsImapProtocol::OnStopRequest(nsIURI* aURL, nsresult aStatus, cons
// End of nsIStreamListenerSupport
//////////////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsImapProtocol::GetDisplayStream (nsIWebShell **webShell)
NS_IMETHODIMP nsImapProtocol::GetStreamConsumer (nsISupports **result)
{
if (webShell)
if (result)
{
*webShell = m_displayConsumer;
NS_IF_ADDREF(*webShell);
*result = m_streamConsumer;
NS_IF_ADDREF(*result);
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP
nsImapProtocol::GetRunningUrl(nsIURI **result)
{
if (result && m_runningUrl)
return m_runningUrl->QueryInterface(nsIURI::GetIID(), (void**)
result);
else
return NS_ERROR_NULL_POINTER;
}
/*
* Writes the data contained in dataBuffer into the current output stream. It also informs
* the transport layer that this data is now available for transmission.
@ -1044,7 +1061,7 @@ nsresult nsImapProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
if (aURL)
{
if (aConsumer)
m_displayConsumer = do_QueryInterface(aConsumer);
m_streamConsumer = do_QueryInterface(aConsumer, &rv);
rv = SetupWithUrl(aURL, aConsumer);
if (NS_FAILED(rv)) return rv;
@ -2553,7 +2570,10 @@ void nsImapProtocol::NormalMessageEndDownload()
m_imapMailFolderSink->NormalEndHeaderParseStream(this);
}
else if (m_imapMessageSink)
{
m_imapMessageSink->NormalEndMsgWriteStream(this);
WaitForFEEventCompletion();
}
}
@ -3276,9 +3296,9 @@ void nsImapProtocol::SetCopyResponseUid(nsMsgKeyArray* aKeyArray,
{
if (m_imapExtensionSink)
{
void* copyState = nsnull;
nsCOMPtr<nsISupports> copyState;
if (m_runningUrl)
m_runningUrl->GetCopyState(&copyState);
m_runningUrl->GetCopyState(getter_AddRefs(copyState));
m_imapExtensionSink->SetCopyResponseUid(this,aKeyArray, msgIdString,
copyState);
WaitForFEEventCompletion();
@ -4207,9 +4227,9 @@ void nsImapProtocol::UploadMessageFromFile (nsIFileSpec* fileSpec,
if (GetServerStateParser().LastCommandSuccessful() &&
imapAction == nsIImapUrl::nsImapAppendDraftFromFile)
{
void* copyState = nsnull;
nsCOMPtr<nsISupports> copyState;
if(m_runningUrl)
m_runningUrl->GetCopyState(&copyState);
m_runningUrl->GetCopyState(getter_AddRefs(copyState));
if (GetServerStateParser().GetCapabilityFlag() &
kUidplusCapability)

Просмотреть файл

@ -107,7 +107,8 @@ public:
NS_IMETHOD GetFlagsForUID(PRUint32 uid, PRBool *foundIt, imapMessageFlagsType *flags);
NS_IMETHOD GetSupportedUserFlags(PRUint16 *flags);
NS_IMETHOD GetDisplayStream (nsIWebShell **webShell);
NS_IMETHOD GetStreamConsumer (nsISupports **aSupport);
NS_IMETHOD GetRunningUrl(nsIURI **aUrl);
// Tell thread to die. This can only be called by imap service
NS_IMETHOD TellThreadToDie(PRBool isSafeToClose);
// Get last active time stamp
@ -290,7 +291,9 @@ private:
nsCOMPtr<nsIOutputStream> m_outputStream; // this will be obtained from the transport interface
nsCOMPtr<nsIStreamListener> m_outputConsumer; // this will be obtained from the transport interface
nsCOMPtr<nsIWebShell> m_displayConsumer; // if we are displaying an article this is the rfc-822 display sink...
nsCOMPtr<nsISupports> m_streamConsumer; // if we are displaying an
// article this is the
// rfc-822 display sink...
// this is a method designed to buffer data coming from the input stream and efficiently extract out
// a line on each call. We read out as much of the stream as we can and store the extra that doesn't

Просмотреть файл

@ -680,7 +680,10 @@ nsImapMessageSinkProxy::NormalEndMsgWriteStream(nsIImapProtocol* aProtocol)
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
{
ev->SetNotifyCompletion(PR_TRUE);
ev->PostEvent(m_eventQueue);
}
}
else
{
@ -1110,7 +1113,7 @@ NS_IMETHODIMP
nsImapExtensionSinkProxy::SetCopyResponseUid(nsIImapProtocol* aProtocol,
nsMsgKeyArray* aKeyArray,
const char* msgIdString,
void* copyState)
nsISupports* copyState)
{
nsresult res = NS_OK;
NS_PRECONDITION (aKeyArray, "Oops... null aKeyArray");
@ -1144,7 +1147,7 @@ nsImapExtensionSinkProxy::SetCopyResponseUid(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapExtensionSinkProxy::SetAppendMsgUid(nsIImapProtocol* aProtocol,
nsMsgKey aKey,
void* copyState)
nsISupports* copyState)
{
nsresult res = NS_OK;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
@ -1173,7 +1176,7 @@ nsImapExtensionSinkProxy::SetAppendMsgUid(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapExtensionSinkProxy::GetMessageId(nsIImapProtocol* aProtocol,
nsString2* messageId,
void* copyState)
nsISupports* copyState)
{
nsresult res = NS_OK;
NS_ASSERTION (m_protocol == aProtocol, "Ooh ooh, wrong protocol");
@ -1808,7 +1811,7 @@ nsImapMiscellaneousSinkProxy::LoadNextQueuedUrl(nsIImapProtocol* aProtocol,
NS_IMETHODIMP
nsImapMiscellaneousSinkProxy::CopyNextStreamMessage(nsIImapProtocol* aProtocol,
void* copyState)
nsISupports* copyState)
{
nsresult res = NS_OK;
NS_PRECONDITION (copyState, "Oops... null copyState");
@ -1823,7 +1826,10 @@ nsImapMiscellaneousSinkProxy::CopyNextStreamMessage(nsIImapProtocol* aProtocol,
if(nsnull == ev)
res = NS_ERROR_OUT_OF_MEMORY;
else
{
ev->SetNotifyCompletion(PR_TRUE);
ev->PostEvent(m_eventQueue);
}
}
else
{
@ -2972,7 +2978,7 @@ SetFolderAdminURLProxyEvent::HandleEvent()
SetCopyResponseUidProxyEvent::SetCopyResponseUidProxyEvent(
nsImapExtensionSinkProxy* aProxy, nsMsgKeyArray* aKeyArray,
const char* msgIdString, void* copyState) :
const char* msgIdString, nsISupports* copyState) :
nsImapExtensionSinkProxyEvent(aProxy), m_msgIdString(msgIdString, eOneByte)
{
NS_ASSERTION (aKeyArray, "Oops... a null key array");
@ -2980,7 +2986,8 @@ SetCopyResponseUidProxyEvent::SetCopyResponseUidProxyEvent(
{
m_copyKeyArray.CopyArray(aKeyArray);
}
m_copyState = copyState;
if (copyState)
m_copyState = do_QueryInterface(copyState);
}
SetCopyResponseUidProxyEvent::~SetCopyResponseUidProxyEvent()
@ -2999,10 +3006,11 @@ SetCopyResponseUidProxyEvent::HandleEvent()
}
SetAppendMsgUidProxyEvent::SetAppendMsgUidProxyEvent(
nsImapExtensionSinkProxy* aProxy, nsMsgKey aKey, void* copyState) :
nsImapExtensionSinkProxyEvent(aProxy), m_key(aKey),
m_copyState(copyState)
nsImapExtensionSinkProxy* aProxy, nsMsgKey aKey, nsISupports* copyState) :
nsImapExtensionSinkProxyEvent(aProxy), m_key(aKey)
{
if (copyState)
m_copyState = do_QueryInterface(copyState);
}
SetAppendMsgUidProxyEvent::~SetAppendMsgUidProxyEvent()
@ -3020,10 +3028,12 @@ SetAppendMsgUidProxyEvent::HandleEvent()
}
GetMessageIdProxyEvent::GetMessageIdProxyEvent(
nsImapExtensionSinkProxy* aProxy, nsString2* messageId, void* copyState) :
nsImapExtensionSinkProxyEvent(aProxy), m_messageId(messageId),
m_copyState(copyState)
nsImapExtensionSinkProxy* aProxy, nsString2* messageId,
nsISupports* copyState) :
nsImapExtensionSinkProxyEvent(aProxy), m_messageId(messageId)
{
if (copyState)
m_copyState = do_QueryInterface(copyState);
}
GetMessageIdProxyEvent::~GetMessageIdProxyEvent()
@ -3624,13 +3634,13 @@ LoadNextQueuedUrlProxyEvent::HandleEvent()
}
CopyNextStreamMessageProxyEvent::CopyNextStreamMessageProxyEvent(
nsImapMiscellaneousSinkProxy* aProxy, void* copyState) :
nsImapMiscellaneousSinkProxy* aProxy, nsISupports* copyState) :
nsImapMiscellaneousSinkProxyEvent(aProxy)
{
NS_ASSERTION (copyState, "Oops... a null copy state");
// potential ownership/lifetime problem here, but incoming server
// shouldn't be deleted while urls are running.
m_copyState = copyState;
m_copyState = do_QueryInterface(copyState);
}
CopyNextStreamMessageProxyEvent::~CopyNextStreamMessageProxyEvent()

Просмотреть файл

@ -182,13 +182,13 @@ public:
NS_IMETHOD SetCopyResponseUid(nsIImapProtocol* aProtocol,
nsMsgKeyArray* aKeyArray,
const char* msgIdString,
void* copyState);
nsISupports* copyState);
NS_IMETHOD SetAppendMsgUid(nsIImapProtocol* aProtocol,
nsMsgKey aKey,
void* copyState);
nsISupports* copyState);
NS_IMETHOD GetMessageId(nsIImapProtocol* aProtocol,
nsString2* messageId,
void* copyState);
nsISupports* copyState);
nsIImapExtensionSink* m_realImapExtensionSink;
};
@ -248,7 +248,7 @@ public:
NS_IMETHOD LoadNextQueuedUrl(nsIImapProtocol* aProtocol,
nsIImapIncomingServer *aInfo);
NS_IMETHOD CopyNextStreamMessage(nsIImapProtocol* aProtocl,
void* copyState);
nsISupports* copyState);
nsIImapMiscellaneousSink* m_realImapMiscellaneousSink;
};
@ -591,32 +591,32 @@ struct SetCopyResponseUidProxyEvent : nsImapExtensionSinkProxyEvent
SetCopyResponseUidProxyEvent(nsImapExtensionSinkProxy* aProxy,
nsMsgKeyArray* aKeyArray,
const char* msgIdString,
void* copyState);
nsISupports* copyState);
virtual ~SetCopyResponseUidProxyEvent();
NS_IMETHOD HandleEvent();
nsMsgKeyArray m_copyKeyArray;
nsString2 m_msgIdString;
void* m_copyState;
nsCOMPtr<nsISupports> m_copyState;
};
struct SetAppendMsgUidProxyEvent : nsImapExtensionSinkProxyEvent
{
SetAppendMsgUidProxyEvent(nsImapExtensionSinkProxy* aProxy,
nsMsgKey aKey, void* copyState);
nsMsgKey aKey, nsISupports* copyState);
virtual ~SetAppendMsgUidProxyEvent();
NS_IMETHOD HandleEvent();
nsMsgKey m_key;
void* m_copyState;
nsCOMPtr<nsISupports> m_copyState;
};
struct GetMessageIdProxyEvent : nsImapExtensionSinkProxyEvent
{
GetMessageIdProxyEvent(nsImapExtensionSinkProxy* aProxy,
nsString2* messageId, void* copyState);
nsString2* messageId, nsISupports* copyState);
virtual ~GetMessageIdProxyEvent();
NS_IMETHOD HandleEvent();
nsString2* m_messageId;
void* m_copyState;
nsCOMPtr<nsISupports> m_copyState;
};
struct nsImapMiscellaneousSinkProxyEvent : public nsImapEvent
@ -821,10 +821,10 @@ struct LoadNextQueuedUrlProxyEvent : public nsImapMiscellaneousSinkProxyEvent
struct CopyNextStreamMessageProxyEvent : public nsImapMiscellaneousSinkProxyEvent
{
CopyNextStreamMessageProxyEvent(nsImapMiscellaneousSinkProxy* aProxy,
void* copyState);
nsISupports* copyState);
virtual ~CopyNextStreamMessageProxyEvent();
NS_IMETHOD HandleEvent();
void* m_copyState;
nsCOMPtr<nsISupports> m_copyState;
};
#endif

Просмотреть файл

@ -259,7 +259,14 @@ NS_IMETHODIMP
nsImapService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListener * aMailboxCopy, PRBool moveMessage,
nsIUrlListener * aUrlListener, nsIURI **aURL)
{
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv = NS_ERROR_NULL_POINTER;
nsCOMPtr<nsISupports> streamSupport;
if (!aSrcMailboxURI || !aMailboxCopy) return rv;
streamSupport = do_QueryInterface(aMailboxCopy, &rv);
if (NS_SUCCEEDED(rv))
rv = DisplayMessage(aSrcMailboxURI, streamSupport, aUrlListener,
aURL);
return rv;
}
NS_IMETHODIMP nsImapService::SaveMessageToDisk(const char *aMessageURI, nsIFileSpec *aFile,
@ -1015,7 +1022,7 @@ nsImapService::OnlineMessageCopy(nsIEventQueue* aClientEventQueue,
PRBool isMove,
nsIUrlListener* aUrlListener,
nsIURI** aURL,
void* copyState)
nsISupports* copyState)
{
NS_ASSERTION(aSrcFolder && aDstFolder && messageIds && aClientEventQueue,
"Fatal ... missing key parameters");
@ -1121,7 +1128,7 @@ nsImapService::AppendMessageFromFile(nsIEventQueue* aClientEventQueue,
PRBool inSelectedState, // needs to be in
nsIUrlListener* aListener,
nsIURI** aURL,
void* aCopyState)
nsISupports* aCopyState)
{
nsresult rv = NS_ERROR_NULL_POINTER;
if (!aClientEventQueue || !aFileSpec || !aDstFolder)

Просмотреть файл

@ -136,7 +136,7 @@ public:
PRBool isMove,
nsIUrlListener* aUrlListener,
nsIURI** aURL,
void* copyState);
nsISupports* copyState);
NS_IMETHOD AppendMessageFromFile(nsIEventQueue* aClientEventQ,
nsIFileSpec* aFileSpec,
nsIMsgFolder* aDstFolder,
@ -145,7 +145,7 @@ public:
PRBool inSelectedState, // needs to be in
nsIUrlListener* aUrlListener,
nsIURI** aURL,
void* copyState);
nsISupports* copyState);
////////////////////////////////////////////////////////////////////////////////////////
// End support of nsIImapService interface
////////////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -40,6 +40,7 @@
#include "nsCOMPtr.h"
#include "nsIImapIncomingServer.h"
#include "nsMsgBaseCID.h"
#include "nsImapUtils.h"
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kCImapHostSessionListCID, NS_IIMAPHOSTSESSIONLIST_CID);
@ -80,7 +81,27 @@ nsImapUrl::~nsImapUrl()
PR_FREEIF(m_userName);
}
NS_IMPL_ISUPPORTS_INHERITED(nsImapUrl, nsMsgMailNewsUrl, nsIImapUrl)
NS_IMPL_ADDREF_INHERITED(nsImapUrl, nsMsgMailNewsUrl)
NS_IMPL_RELEASE_INHERITED(nsImapUrl, nsMsgMailNewsUrl)
NS_IMETHODIMP
nsImapUrl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
*aInstancePtr = nsnull;
if (aIID.Equals(nsIImapUrl::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIImapUrl*, this);
else if (aIID.Equals(nsIMsgUriUrl::GetIID()))
*aInstancePtr = NS_STATIC_CAST(nsIMsgUriUrl*, this);
if(*aInstancePtr)
{
NS_ADDREF_THIS();
return NS_OK;
}
return nsMsgMailNewsUrl::QueryInterface(aIID, aInstancePtr);
}
////////////////////////////////////////////////////////////////////////////////////
// Begin nsIImapUrl specific support
@ -1006,20 +1027,22 @@ NS_IMETHODIMP nsImapUrl::SetAllowContentChange(PRBool allowContentChange)
return NS_OK;
}
NS_IMETHODIMP nsImapUrl::SetCopyState(void* copyState)
NS_IMETHODIMP nsImapUrl::SetCopyState(nsISupports* copyState)
{
if (!copyState) return NS_ERROR_NULL_POINTER;
NS_LOCK_INSTANCE();
m_copyState = copyState;
m_copyState = null_nsCOMPtr();
m_copyState = do_QueryInterface(copyState);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
NS_IMETHODIMP nsImapUrl::GetCopyState(void** copyState)
NS_IMETHODIMP nsImapUrl::GetCopyState(nsISupports** copyState)
{
if (!copyState) return NS_ERROR_NULL_POINTER;
NS_LOCK_INSTANCE();
*copyState = m_copyState;
NS_IF_ADDREF(*copyState);
NS_UNLOCK_INSTANCE();
if (*copyState) return NS_OK;
return NS_ERROR_NULL_POINTER;
@ -1059,6 +1082,18 @@ NS_IMETHODIMP nsImapUrl::GetAllowContentChange(PRBool *result)
return NS_OK;
}
NS_IMETHODIMP
nsImapUrl::GetURI(char** aURI)
{
nsresult rv = NS_ERROR_NULL_POINTER;
if (aURI)
{
*aURI = nsnull;
PRUint32 key = m_listOfMessageIds ? atoi(m_listOfMessageIds) : 0;
return nsBuildImapMessageURI(m_file, key, aURI);
}
return rv;
}
char *nsImapUrl::ReplaceCharsInCopiedString(const char *stringToCopy, char oldChar, char newChar)
{

Просмотреть файл

@ -24,7 +24,7 @@
#include "nsMsgMailNewsUrl.h"
#include "nsIMsgIncomingServer.h"
class nsImapUrl : public nsIImapUrl, public nsMsgMailNewsUrl
class nsImapUrl : public nsIImapUrl, public nsMsgMailNewsUrl, public nsIMsgUriUrl
{
public:
@ -78,12 +78,15 @@ public:
NS_IMETHOD SetAllowContentChange(PRBool allowContentChange);
NS_IMETHOD GetAllowContentChange(PRBool *results);
NS_IMETHOD SetCopyState(void* copyState);
NS_IMETHOD GetCopyState(void** copyState);
NS_IMETHOD SetCopyState(nsISupports* copyState);
NS_IMETHOD GetCopyState(nsISupports** copyState);
NS_IMETHOD SetMsgFileSpec(nsIFileSpec* fileSpec);
NS_IMETHOD GetMsgFileSpec(nsIFileSpec** fileSpec);
// nsIMsgUriUrl
NS_IMETHOD GetURI(char **aURI);
// nsImapUrl
nsImapUrl();
virtual ~nsImapUrl();
@ -133,7 +136,7 @@ protected:
nsCOMPtr<nsIMsgIncomingServer> m_server;
// online message copy support; i don't have a better solution yet
void* m_copyState;
nsCOMPtr<nsISupports> m_copyState;
nsCOMPtr<nsIFileSpec> m_fileSpec;
};

Просмотреть файл

@ -291,6 +291,4 @@ nsresult nsBuildImapMessageURI(const char *baseURI, PRUint32 key, char** uri)
delete[] tail;
return NS_OK;
}

Просмотреть файл

@ -67,28 +67,28 @@ static NS_DEFINE_CID(kMsgCopyServiceCID, NS_MSGCOPYSERVICE_CID);
/////////////////////////////////////////////////////////////////////////////
nsLocalMailCopyState::nsLocalMailCopyState() :
fileStream(nsnull), messageService(nsnull),
curCopyIndex(0), curDstKey(0xffffffff),
totalMsgCount(0)
m_fileStream(nsnull), m_curDstKey(0xffffffff), m_curCopyIndex(0),
m_messageService(nsnull), m_totalMsgCount(0), m_isMove(PR_FALSE),
m_dummyEnvelopeNeeded(PR_FALSE)
{
}
nsLocalMailCopyState::~nsLocalMailCopyState()
{
if (fileStream)
if (m_fileStream)
{
fileStream->close();
delete fileStream;
m_fileStream->close();
delete m_fileStream;
}
if (messageService)
if (m_messageService)
{
nsCOMPtr<nsIRDFResource> msgNode(do_QueryInterface(message));
nsCOMPtr<nsIRDFResource> msgNode(do_QueryInterface(m_message));
if (msgNode)
{
char* uri;
msgNode->GetValue(&uri);
if (uri)
ReleaseMessageServiceFromURI(uri, messageService);
ReleaseMessageServiceFromURI(uri, m_messageService);
}
}
}
@ -1225,24 +1225,24 @@ nsMsgLocalMailFolder::InitCopyState(nsISupports* aSupport,
//Before we continue we should verify that there is enough diskspace.
//XXX How do we do this?
mCopyState->fileStream = new nsOutputFileStream(path, PR_WRONLY |
mCopyState->m_fileStream = new nsOutputFileStream(path, PR_WRONLY |
PR_CREATE_FILE);
if(!mCopyState->fileStream)
if(!mCopyState->m_fileStream)
{
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
//The new key is the end of the file
mCopyState->fileStream->seek(PR_SEEK_END, 0);
mCopyState->srcSupport = do_QueryInterface(aSupport, &rv);
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
mCopyState->m_srcSupport = do_QueryInterface(aSupport, &rv);
if (NS_FAILED(rv)) goto done;
mCopyState->messages = do_QueryInterface(messages, &rv);
mCopyState->m_messages = do_QueryInterface(messages, &rv);
if (NS_FAILED(rv)) goto done;
mCopyState->curCopyIndex = 0;
mCopyState->isMove = isMove;
rv = messages->Count(&mCopyState->totalMsgCount);
mCopyState->m_curCopyIndex = 0;
mCopyState->m_isMove = isMove;
rv = messages->Count(&mCopyState->m_totalMsgCount);
if (listener)
mCopyState->listener = do_QueryInterface(listener, &rv);
mCopyState->m_listener = do_QueryInterface(listener, &rv);
done:
@ -1283,6 +1283,24 @@ nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
rv = InitCopyState(aSupport, messages, isMove, listener);
if (NS_FAILED(rv)) return rv;
char *uri = nsnull;
rv = srcFolder->GetURI(&uri);
nsString2 protocolType(uri, eOneByte);
protocolType.SetLength(protocolType.Find(':'));
if (!protocolType.EqualsIgnoreCase("mailbox"))
{
mCopyState->m_dummyEnvelopeNeeded = PR_TRUE;
nsParseMailMessageState* parseMsgState = new nsParseMailMessageState();
if (parseMsgState)
{
nsCOMPtr<nsIMsgDatabase> msgDb;
mCopyState->m_parseMsgState = do_QueryInterface(parseMsgState, &rv);
rv = GetMsgDatabase(getter_AddRefs(msgDb));
if (msgDb)
parseMsgState->SetMailDB(msgDb);
}
}
// undo stuff
nsLocalMoveCopyMsgTxn* msgTxn = nsnull;
@ -1290,7 +1308,7 @@ nsMsgLocalMailFolder::CopyMessages(nsIMsgFolder* srcFolder, nsISupportsArray*
msgTxn = new nsLocalMoveCopyMsgTxn(srcFolder, this, isMove);
if (msgTxn)
mCopyState->undoMsgTxn = do_QueryInterface(msgTxn, &rv);
mCopyState->m_undoMsgTxn = do_QueryInterface(msgTxn, &rv);
else
rv = NS_ERROR_OUT_OF_MEMORY;
@ -1349,7 +1367,7 @@ nsMsgLocalMailFolder::CopyFileMessage(nsIFileSpec* fileSpec, nsIMessage*
if (parseMsgState)
{
nsCOMPtr<nsIMsgDatabase> msgDb;
mCopyState->parseMsgState = do_QueryInterface(parseMsgState, &rv);
mCopyState->m_parseMsgState = do_QueryInterface(parseMsgState, &rv);
rv = GetMsgDatabase(getter_AddRefs(msgDb));
if (msgDb)
parseMsgState->SetMailDB(msgDb);
@ -1504,17 +1522,37 @@ NS_IMETHODIMP nsMsgLocalMailFolder::BeginCopy(nsIMessage *message)
{
if (!mCopyState) return NS_ERROR_NULL_POINTER;
nsresult rv = NS_OK;
mCopyState->curDstKey = mCopyState->fileStream->tell();
mCopyState->m_curDstKey = mCopyState->m_fileStream->tell();
// CopyFileMessage() only
if (mCopyState->parseMsgState)
// CopyFileMessage() and CopyMessages() from servers other than pop3
if (mCopyState->m_parseMsgState)
{
mCopyState->parseMsgState->SetEnvelopePos(mCopyState->curDstKey);
mCopyState->parseMsgState->SetState(nsIMsgParseMailMsgState::ParseHeadersState);
mCopyState->m_parseMsgState->SetEnvelopePos(mCopyState->m_curDstKey);
mCopyState->m_parseMsgState->SetState(nsIMsgParseMailMsgState::ParseHeadersState);
}
if (mCopyState->m_dummyEnvelopeNeeded)
{
static char result[75];
char timeBuffer[128];
PRExplodedTime now;
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &now);
PR_FormatTimeUSEnglish(timeBuffer, sizeof(timeBuffer),
"%a %b %d %H:%M:%S %Y",
&now);
PL_strcpy(result, "From - ");
PL_strcpy(result + 7, timeBuffer);
PL_strcpy(result + 7 + 24, MSG_LINEBREAK);
// *** jt - hard code status line for now; come back later
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
*(mCopyState->m_fileStream) << result;
*(mCopyState->m_fileStream) << "X-Mozilla-Status: 0001";
*(mCopyState->m_fileStream) << MSG_LINEBREAK;
*(mCopyState->m_fileStream) << "X-Mozilla-Status2: 00000000";
*(mCopyState->m_fileStream) << MSG_LINEBREAK;
}
if (message)
mCopyState->message = do_QueryInterface(message, &rv);
mCopyState->m_message = do_QueryInterface(message, &rv);
return rv;
}
@ -1539,23 +1577,23 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CopyData(nsIInputStream *aIStream, PRInt32 a
if (aLength < (PRInt32) maxReadCount)
maxReadCount = aLength;
rv = aIStream->Read(mCopyState->dataBuffer, maxReadCount, &readCount);
mCopyState->dataBuffer[readCount] ='\0';
mCopyState->fileStream->seek(PR_SEEK_END, 0);
*(mCopyState->fileStream) << mCopyState->dataBuffer;
rv = aIStream->Read(mCopyState->m_dataBuffer, maxReadCount, &readCount);
mCopyState->m_dataBuffer[readCount] ='\0';
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
*(mCopyState->m_fileStream) << mCopyState->m_dataBuffer;
// CopyFileMessage() only
if (mCopyState->parseMsgState)
// CopyFileMessage() and CopyMessages() from servers other than mailbox
if (mCopyState->m_parseMsgState)
{
char* start = mCopyState->dataBuffer;
char* end = PL_strstr(mCopyState->dataBuffer, CRLF);
char* start = mCopyState->m_dataBuffer;
char* end = PL_strstr(mCopyState->m_dataBuffer, CRLF);
while (start && end)
{
// +2 counting for the CRLF
mCopyState->parseMsgState->ParseAFolderLine(start, end-start+2);
mCopyState->m_parseMsgState->ParseAFolderLine(start, end-start+2);
start = end+2;
if (start >= &mCopyState->dataBuffer[readCount])
if (start >= &mCopyState->m_dataBuffer[readCount])
break;
end = PL_strstr(start, CRLF);
}
@ -1572,12 +1610,12 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
nsresult rv = copySucceeded ? NS_OK : NS_ERROR_FAILURE;
//Copy the header to the new database
if(copySucceeded && mCopyState->message)
if(copySucceeded && mCopyState->m_message)
{ // CopyMessages() goes here; CopyFileMessage() never gets in here because
// the mCopyState->message will be always null for file message
// the mCopyState->m_message will be always null for file message
nsCOMPtr<nsIMsgDBHdr> newHdr;
nsCOMPtr<nsIMsgDBHdr> msgDBHdr;
nsCOMPtr<nsIDBMessage> dbMessage(do_QueryInterface(mCopyState->message,
nsCOMPtr<nsIDBMessage> dbMessage(do_QueryInterface(mCopyState->m_message,
&rv));
rv = dbMessage->GetMsgDBHdr(getter_AddRefs(msgDBHdr));
@ -1586,29 +1624,55 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
rv = GetDatabase();
if(NS_SUCCEEDED(rv))
rv = mDatabase->CopyHdrFromExistingHdr(mCopyState->curDstKey, msgDBHdr,
rv = mDatabase->CopyHdrFromExistingHdr(mCopyState->m_curDstKey, msgDBHdr,
getter_AddRefs(newHdr));
if (NS_SUCCEEDED(rv) && mCopyState->undoMsgTxn)
if (NS_SUCCEEDED(rv) && mCopyState->m_undoMsgTxn)
{
nsCOMPtr<nsLocalMoveCopyMsgTxn>
localUndoTxn(do_QueryInterface(mCopyState->undoMsgTxn));
localUndoTxn(do_QueryInterface(mCopyState->m_undoMsgTxn));
nsMsgKey aKey;
msgDBHdr->GetMessageKey(&aKey);
localUndoTxn->AddSrcKey(aKey);
localUndoTxn->AddDstKey(mCopyState->curDstKey);
localUndoTxn->AddDstKey(mCopyState->m_curDstKey);
}
}
mCopyState->curCopyIndex++;
if (mCopyState->m_dummyEnvelopeNeeded)
{
mCopyState->m_fileStream->seek(PR_SEEK_END, 0);
*(mCopyState->m_fileStream) << MSG_LINEBREAK;
}
if (mCopyState->curCopyIndex < mCopyState->totalMsgCount)
// CopyFileMessage() and CopyMessages() from servers other than mailbox
if (mCopyState->m_parseMsgState)
{
nsresult result;
nsCOMPtr<nsIMsgDatabase> msgDb;
nsCOMPtr<nsIMsgDBHdr> newHdr;
result =
mCopyState->m_parseMsgState->GetNewMsgHdr(getter_AddRefs(newHdr));
if (NS_SUCCEEDED(result) && newHdr)
{
result = GetMsgDatabase(getter_AddRefs(msgDb));
if (NS_SUCCEEDED(result) && msgDb)
msgDb->AddNewHdrToDB(newHdr, PR_TRUE);
}
mCopyState->m_parseMsgState->Clear();
if (mCopyState->m_listener) // CopyFileMessage() only
mCopyState->m_listener->SetMessageKey((PRUint32) mCopyState->m_curDstKey);
}
mCopyState->m_curCopyIndex++;
if (mCopyState->m_curCopyIndex < mCopyState->m_totalMsgCount)
{ // CopyMessages() goes here; CopyFileMessage() never gets in here because
// curCopyIndex will always be less than the mCopyState->totalMsgCount
// curCopyIndex will always be less than the mCopyState->m_totalMsgCount
nsCOMPtr<nsISupports> aSupport =
getter_AddRefs(mCopyState->messages->ElementAt(mCopyState->curCopyIndex));
mCopyState->message = do_QueryInterface(aSupport, &rv);
getter_AddRefs(mCopyState->m_messages->ElementAt(mCopyState->m_curCopyIndex));
mCopyState->m_message = do_QueryInterface(aSupport, &rv);
if (NS_SUCCEEDED(rv))
rv = CopyMessageTo(mCopyState->message, this, mCopyState->isMove);
rv = CopyMessageTo(mCopyState->m_message, this, mCopyState->m_isMove);
}
else
{ // both CopyMessages() & CopyFileMessage() go here if they have
@ -1618,27 +1682,10 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(PRBool copySucceeded)
kMsgCopyServiceCID, &result);
if (NS_SUCCEEDED(result))
copyService->NotifyCompletion(mCopyState->srcSupport, this, rv);
// CopyFileMessage() only
if (mCopyState->parseMsgState)
{
nsCOMPtr<nsIMsgDatabase> msgDb;
nsCOMPtr<nsIMsgDBHdr> newHdr;
result =
mCopyState->parseMsgState->GetNewMsgHdr(getter_AddRefs(newHdr));
if (NS_SUCCEEDED(result) && newHdr)
{
result = GetMsgDatabase(getter_AddRefs(msgDb));
if (NS_SUCCEEDED(result) && msgDb)
msgDb->AddNewHdrToDB(newHdr, PR_TRUE);
}
if (mCopyState->listener)
mCopyState->listener->SetMessageKey((PRUint32) mCopyState->curDstKey);
}
copyService->NotifyCompletion(mCopyState->m_srcSupport, this, rv);
if (mTxnMgr && NS_SUCCEEDED(rv) && mCopyState->undoMsgTxn)
mTxnMgr->Do(mCopyState->undoMsgTxn);
if (mTxnMgr && NS_SUCCEEDED(rv) && mCopyState->m_undoMsgTxn)
mTxnMgr->Do(mCopyState->m_undoMsgTxn);
ClearCopyState();
}
@ -1671,7 +1718,7 @@ nsresult nsMsgLocalMailFolder::CopyMessageTo(nsIMessage *message,
if(!copyListener)
return NS_ERROR_NO_INTERFACE;
nsCOMPtr<nsIMsgFolder> srcFolder(do_QueryInterface(mCopyState->srcSupport));
nsCOMPtr<nsIMsgFolder> srcFolder(do_QueryInterface(mCopyState->m_srcSupport));
if(!srcFolder)
return NS_ERROR_NO_INTERFACE;
@ -1679,19 +1726,19 @@ nsresult nsMsgLocalMailFolder::CopyMessageTo(nsIMessage *message,
if(NS_FAILED(rv))
return rv;
if (!mCopyState->messageService)
if (!mCopyState->m_messageService)
{
rv = GetMessageServiceFromURI(uri, &mCopyState->messageService);
rv = GetMessageServiceFromURI(uri, &mCopyState->m_messageService);
}
if (NS_SUCCEEDED(rv) && mCopyState->messageService)
if (NS_SUCCEEDED(rv) && mCopyState->m_messageService)
{
nsIURI * url = nsnull;
nsCOMPtr<nsIStreamListener>
streamListener(do_QueryInterface(copyStreamListener));
if(!streamListener)
return NS_ERROR_NO_INTERFACE;
mCopyState->messageService->CopyMessage(uri, streamListener, isMove,
mCopyState->m_messageService->CopyMessage(uri, streamListener, isMove,
nsnull, &url);
}

Просмотреть файл

@ -41,20 +41,21 @@ struct nsLocalMailCopyState
nsLocalMailCopyState();
virtual ~nsLocalMailCopyState();
nsOutputFileStream* fileStream;
nsCOMPtr<nsISupports> srcSupport;
nsCOMPtr<nsISupportsArray> messages;
nsCOMPtr<nsMsgTxn> undoMsgTxn;
nsCOMPtr<nsIMessage> message; // current copy message
nsCOMPtr<nsIMsgParseMailMsgState> parseMsgState;
nsCOMPtr<nsIMsgCopyServiceListener> listener;
nsOutputFileStream* m_fileStream;
nsCOMPtr<nsISupports> m_srcSupport;
nsCOMPtr<nsISupportsArray> m_messages;
nsCOMPtr<nsMsgTxn> m_undoMsgTxn;
nsCOMPtr<nsIMessage> m_message; // current copy message
nsCOMPtr<nsIMsgParseMailMsgState> m_parseMsgState;
nsCOMPtr<nsIMsgCopyServiceListener> m_listener;
nsIMsgMessageService* messageService;
PRBool isMove;
PRUint32 curCopyIndex;
nsMsgKey curDstKey;
PRUint32 totalMsgCount;
char dataBuffer[FOUR_K];
nsIMsgMessageService* m_messageService;
PRBool m_isMove;
PRBool m_dummyEnvelopeNeeded;
nsMsgKey m_curDstKey;
PRUint32 m_curCopyIndex;
PRUint32 m_totalMsgCount;
char m_dataBuffer[FOUR_K];
};
class nsMsgLocalMailFolder : public nsMsgDBFolder,

Просмотреть файл

@ -74,6 +74,45 @@
#define DEFAULT_NEWS_CHUNK_SIZE -1
// ***jt -- the following were pirated from xpcom/io/nsByteBufferInputStream
// which is not currently in the build system
class nsDummyBufferStream : public nsIInputStream
{
public:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close(void) {
NS_NOTREACHED("nsDummyBufferStream::Close");
return NS_ERROR_FAILURE;
}
// nsIInputStream methods:
NS_IMETHOD GetLength(PRUint32 *aLength) {
*aLength = mLength;
return NS_OK;
}
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
PRUint32 amt = PR_MIN(aCount, mLength);
if (amt > 0) {
nsCRT::memcpy(aBuf, mBuffer, amt);
mBuffer += amt;
mLength -= amt;
}
*aReadCount = amt;
return NS_OK;
}
// nsDummyBufferStream methods:
nsDummyBufferStream(const char* buffer, PRUint32 length)
: mBuffer(buffer), mLength(length) {NS_INIT_REFCNT();}
virtual ~nsDummyBufferStream() {}
protected:
const char* mBuffer;
PRUint32 mLength;
};
// move these to a string bundle
#define UNTIL_STRING_BUNDLES_XP_HTML_NEWS_ERROR "<TITLE>Error!</TITLE>\n<H1>Error!</H1> newsgroup server responded: <b>%.256s</b><p>\n"
#define UNTIL_STRING_BUNDLES_XP_HTML_ARTICLE_EXPIRED "<b><p>Perhaps the article has expired</b><p>\n"
@ -377,6 +416,22 @@ char *MSG_UnEscapeSearchUrl (const char *commandSpecificData)
// END OF TEMPORARY HARD CODED FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////
NS_IMPL_ADDREF(nsDummyBufferStream)
NS_IMPL_RELEASE(nsDummyBufferStream)
NS_IMETHODIMP
nsDummyBufferStream::QueryInterface(REFNSIID aIID, void** result)
{
if (!result) return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (aIID.Equals(nsIInputStream::GetIID()))
*result = NS_STATIC_CAST(nsIInputStream*, this);
if (*result)
{
AddRef();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
nsNNTPProtocol::nsNNTPProtocol() : m_tempArticleFile(ARTICLE_PATH), m_tempErrorFile(ERROR_PATH)
{
@ -497,7 +552,13 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
// Query the url for its nsINntpUrl interface...assert and fail to load if they passed us a non news url...
if (aConsumer) // did the caller pass in a display stream?
rv = aConsumer->QueryInterface(kIWebShell, getter_AddRefs(m_displayConsumer));
{
rv = aConsumer->QueryInterface(kIWebShell,
getter_AddRefs(m_displayConsumer));
if (NS_FAILED(rv) && !m_displayConsumer) // is this a copy operation
m_copyStreamListener = do_QueryInterface(aConsumer, &rv);
}
if (aURL)
{
@ -2061,11 +2122,23 @@ PRInt32 nsNNTPProtocol::BeginArticle()
// the article to file. We'll then call a load file url on our "temp" file. Then mkfile does all the work
// with talking to the RFC-822->HTML stream converter....clever huh =).....
// we are about to display an article so open up a temp file on the article...
m_tempArticleFile.Delete(PR_FALSE);
nsCOMPtr <nsISupports> supports;
NS_NewIOFileStream(getter_AddRefs(supports), m_tempArticleFile, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700);
m_tempArticleStream = do_QueryInterface(supports);
// we are about to display an article so open up a temp file on the
// article...
if (m_copyStreamListener)
{
m_tempArticleFile.Delete(PR_FALSE);
m_tempArticleStream = null_nsCOMPtr();
nsCOMPtr<nsIURI> aURL(do_QueryInterface(m_runningURL));
m_copyStreamListener->OnStartRequest(aURL, "");
}
else
{
m_tempArticleFile.Delete(PR_FALSE);
nsCOMPtr <nsISupports> supports;
NS_NewIOFileStream(getter_AddRefs(supports), m_tempArticleFile,
PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 00700);
m_tempArticleStream = do_QueryInterface(supports);
}
m_nextState = NNTP_READ_ARTICLE;
return 0;
@ -2100,6 +2173,8 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
if(!line)
return(status); /* no line yet or error */
nsCOMPtr<nsIURI> url = do_QueryInterface(m_runningURL);
if (m_typeWanted == CANCEL_WANTED && m_responseCode != MK_NNTP_RESPONSE_ARTICLE_HEAD)
{
/* HEAD command failed. */
@ -2117,6 +2192,8 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
// and close the article file if it was open....
if (m_tempArticleStream)
m_tempArticleStream->Close();
else if (m_copyStreamListener)
m_copyStreamListener->OnStopRequest(url, 0, nsnull);
if (m_displayConsumer)
{
@ -2181,6 +2258,17 @@ PRInt32 nsNNTPProtocol::ReadArticle(nsIInputStream * inputStream, PRUint32 lengt
PRUint32 count = 0;
m_tempArticleStream->Write(outputBuffer, PL_strlen(outputBuffer), &count);
}
else if (m_copyStreamListener)
{
nsDummyBufferStream *dummyStream =
new nsDummyBufferStream (outputBuffer,
PL_strlen(outputBuffer));
nsCOMPtr<nsIInputStream> aInputStream =
do_QueryInterface(dummyStream);
if (aInputStream)
m_copyStreamListener->OnDataAvailable(url,
aInputStream, PL_strlen(outputBuffer));
}
}
}

Просмотреть файл

@ -190,6 +190,9 @@ private:
nsCOMPtr<nsIOutputStream> m_tempErrorStream;
nsFileSpec m_tempErrorFile;
// uber copy service support
nsCOMPtr<nsIStreamListener> m_copyStreamListener; // per message
// News Event Sinks
nsCOMPtr <nsINNTPNewsgroupList> m_newsgroupList;
nsCOMPtr <nsINNTPArticleList> m_articleList;

Просмотреть файл

@ -254,8 +254,14 @@ nsresult nsBuildNewsMessageURI(const char *baseURI, PRUint32 key, char** uri)
nsAutoString tailURI(baseURI, eOneByte);
// chop off news:/
#if 0
if (tailURI.Find(kNewsRootURI) == 0)
tailURI.Cut(0, kNewsRootURILen);
#else
PRInt32 strOffset = tailURI.Find(":/");
if (strOffset != -1)
tailURI.Cut(0, strOffset+2);
#endif
*uri = PR_smprintf("%s%s#%d", kNewsMessageRootURI, tailURI.GetBuffer(), key);

Просмотреть файл

@ -267,8 +267,13 @@ nsresult nsNntpService::ConvertNewsMessageURI2NewsURI(const char *messageURI, ns
nsresult nsNntpService::CopyMessage(const char * aSrcMailboxURI, nsIStreamListener * aMailboxCopyHandler, PRBool moveMessage,
nsIUrlListener * aUrlListener, nsIURI **aURL)
{
NS_ASSERTION(0, "unimplemented feature");
return NS_OK;
nsresult rv = NS_ERROR_NULL_POINTER;
nsCOMPtr<nsISupports> streamSupport;
if (!aSrcMailboxURI || !aMailboxCopyHandler) return rv;
streamSupport = do_QueryInterface(aMailboxCopyHandler, &rv);
if (NS_SUCCEEDED(rv))
rv = DisplayMessage(aSrcMailboxURI, streamSupport, aUrlListener, aURL);
return rv;
}
nsresult nsNntpService::FindHostFromGroup(nsString &host, nsString &groupName)

Просмотреть файл

@ -243,7 +243,7 @@ NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI)
{
char * uri = nsnull;
nsFileSpec folder = *filePath;
nsBuildNewsMessageURI(m_spec, 0 /* don't have keys yet */, &uri);
nsBuildNewsMessageURI(m_spec, m_messageKey, &uri);
*aURI = uri;
}
else
@ -454,6 +454,10 @@ nsresult nsNntpUrl::ParseUrl(const nsString& aSpec)
#endif
delete [] cSpec;
if (m_filePath)
delete m_filePath;
m_filePath = new nsFileSpec(nsFilePath(m_file));
NS_UNLOCK_INSTANCE();
return NS_OK;
}