зеркало из https://github.com/mozilla/pjs.git
Bug 56670 - add error handling ui to movemail
First set of changes. r/sr=sspitzer@netscape.com
This commit is contained in:
Родитель
9b78be8799
Коммит
35390b3e9f
|
@ -197,3 +197,26 @@
|
|||
## @loc None
|
||||
4030=Mail server does not support secure authentication.
|
||||
|
||||
## @name MOVEMAIL_SPOOL_FILE_NOT_FOUND
|
||||
## @loc None
|
||||
4031=Unable to locate mail spool file.
|
||||
|
||||
## @name MOVEMAIL_SPOOL_FILE_LOCKED
|
||||
## @loc None
|
||||
4032=The mail spool file %S is locked.
|
||||
|
||||
## @name MOVEMAIL_CANT_OPEN_SPOOL_FILE
|
||||
## @loc None
|
||||
4033=Unable to open mail spool file %S.
|
||||
|
||||
## @name MOVEMAIL_CANT_CREATE_LOCK
|
||||
## @loc None
|
||||
4034=Unable to create lock file %S. For movemail to work, it is necessary to create lock files in the mail spool directory. On many systems, this is best accomplished by making the spool directory be mode 01777.
|
||||
|
||||
## @name MOVEMAIL_CANT_DELETE_LOCK
|
||||
## @loc None
|
||||
4035=Unable to delete lock file %S.
|
||||
|
||||
## @name MOVEMAIL_CANT_TRUNCATE_SPOOL_FILE
|
||||
## @loc None
|
||||
4036=Unable to truncate spool file %S.
|
||||
|
|
|
@ -87,5 +87,11 @@ private:
|
|||
#define MOVING_MSGS_STATUS 4028
|
||||
#define POP3_MESSAGE_FOLDER_BUSY 4029
|
||||
#define CANNOT_PROCESS_SECURE_AUTH 4030
|
||||
#define MOVEMAIL_SPOOL_FILE_NOT_FOUND 4031
|
||||
#define MOVEMAIL_SPOOL_FILE_LOCKED 4032
|
||||
#define MOVEMAIL_CANT_OPEN_SPOOL_FILE 4033
|
||||
#define MOVEMAIL_CANT_CREATE_LOCK 4034
|
||||
#define MOVEMAIL_CANT_DELETE_LOCK 4035
|
||||
#define MOVEMAIL_CANT_TRUNCATE_SPOOL_FILE 4036
|
||||
|
||||
#endif /* _nsLocalStringBundle_H__ */
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "nsIMsgMailSession.h"
|
||||
#include "nsParseMailbox.h"
|
||||
#include "nsIFolder.h"
|
||||
#include "nsIPrompt.h"
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsFileStream.h"
|
||||
|
@ -79,6 +80,7 @@ nsMovemailService::nsMovemailService()
|
|||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr, "*** MURRR, new nsMovemailService\n");
|
||||
#endif
|
||||
mStringService = do_GetService(NS_MSG_POPSTRINGSERVICE_CONTRACTID);
|
||||
}
|
||||
|
||||
nsMovemailService::~nsMovemailService()
|
||||
|
@ -106,6 +108,39 @@ nsMovemailService::CheckForNewMail(nsIUrlListener * aUrlListener,
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
nsMovemailService::Error(PRInt32 errorCode,
|
||||
const PRUnichar **params,
|
||||
PRUint32 length)
|
||||
{
|
||||
if (!mStringService) return;
|
||||
if (!mMsgWindow) return;
|
||||
|
||||
nsCOMPtr<nsIPrompt> dialog;
|
||||
nsresult rv = mMsgWindow->GetPromptDialog(getter_AddRefs(dialog));
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
||||
nsXPIDLString errStr;
|
||||
|
||||
// Format the error string if necessary
|
||||
if (params) {
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = mStringService->GetBundle(getter_AddRefs(bundle));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
bundle->FormatStringFromID(errorCode, params, length,
|
||||
getter_Copies(errStr));
|
||||
}
|
||||
else {
|
||||
mStringService->GetStringByID(errorCode, getter_Copies(errStr));
|
||||
}
|
||||
|
||||
if (!errStr.IsEmpty()) {
|
||||
dialog->Alert(nsnull, errStr.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRBool ObtainSpoolLock(const char *spoolnameStr,
|
||||
int seconds /* number of seconds to retry */)
|
||||
{
|
||||
|
@ -128,22 +163,10 @@ PRBool ObtainSpoolLock(const char *spoolnameStr,
|
|||
|
||||
nsresult rv;
|
||||
|
||||
// Create nsFileSpec and nsILocalFile for the spool file
|
||||
nsFileSpec spoollocspec(spoolnameStr);
|
||||
nsCOMPtr<nsILocalFile> spoollocfile;
|
||||
rv = NS_FileSpecToIFile(&spoollocspec, getter_AddRefs(spoollocfile));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
// Create nsFileSpec and nsILocalFile for the spool.mozlock file
|
||||
nsFileSpec tmplocspec(mozlockstr.get());
|
||||
nsCOMPtr<nsILocalFile> tmplocfile;
|
||||
rv = NS_FileSpecToIFile(&tmplocspec, getter_AddRefs(tmplocfile));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
// Create nsFileSpec and nsILocalFile for the spool.lock file
|
||||
nsFileSpec locklocspec(lockstr.get());
|
||||
nsCOMPtr<nsILocalFile> locklocfile;
|
||||
rv = NS_FileSpecToIFile(&locklocspec, getter_AddRefs(locklocfile));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
// THOUGHT: hmm, perhaps use MakeUnique to generate us a unique mozlock?
|
||||
|
@ -306,9 +329,11 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
|
||||
nsCOMPtr<nsIMsgIncomingServer> in_server =
|
||||
do_QueryInterface(movemailServer);
|
||||
if (!in_server)
|
||||
return NS_MSG_INVALID_OR_MISSING_SERVER;
|
||||
mMsgWindow = aMsgWindow;
|
||||
nsCAutoString wholeboxname;
|
||||
|
||||
if (in_server) {
|
||||
in_server->SetServerBusy(PR_TRUE);
|
||||
|
||||
// FUN STUFF starts here
|
||||
|
@ -374,8 +399,7 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (spoolfile &&
|
||||
found_spool_but_it_is_locked) {
|
||||
if (spoolfile && found_spool_but_it_is_locked) {
|
||||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr,
|
||||
"Well, got the spool file but not the lock.\n");
|
||||
|
@ -388,7 +412,6 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
if (!buffer)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
else {
|
||||
if (!spoolfile->failed()) {
|
||||
nsIOFileStream* outFileStream;
|
||||
nsParseNewMailState *newMailParser;
|
||||
|
||||
|
@ -400,15 +423,12 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
nsFileSpec fileSpec;
|
||||
mailDirectory->GetFileSpec(&fileSpec);
|
||||
fileSpec += "Inbox";
|
||||
outFileStream =
|
||||
new nsIOFileStream(fileSpec /*, PR_CREATE_FILE */);
|
||||
if (outFileStream) {
|
||||
outFileStream->seek(fileSpec.GetFileSize());
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
outFileStream = new nsIOFileStream(fileSpec);
|
||||
if (!outFileStream) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto freebuff_and_unlock;
|
||||
}
|
||||
outFileStream->seek(fileSpec.GetFileSize());
|
||||
|
||||
// create a new mail parser
|
||||
newMailParser = new nsParseNewMailState;
|
||||
|
@ -419,24 +439,21 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
|
||||
nsCOMPtr <nsIMsgParseMailMsgState> iParseMailMsgState = NS_STATIC_CAST(nsIMsgParseMailMsgState*, newMailParser);
|
||||
nsCOMPtr <nsIFolder> serverFolder;
|
||||
rv =
|
||||
in_server->GetRootFolder(getter_AddRefs(serverFolder));
|
||||
rv = in_server->GetRootFolder(getter_AddRefs(serverFolder));
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
goto freebuff_and_unlock;
|
||||
|
||||
nsCOMPtr<nsIMsgFolder> inbox;
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIMsgFolder> rootMsgFolder = do_QueryInterface(serverFolder);
|
||||
if(rootMsgFolder)
|
||||
{
|
||||
if (!rootMsgFolder)
|
||||
goto freebuff_and_unlock;
|
||||
PRUint32 numFolders;
|
||||
rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1,
|
||||
&numFolders,
|
||||
getter_AddRefs(inbox));
|
||||
}
|
||||
}
|
||||
if (NS_FAILED(rv))
|
||||
goto freebuff_and_unlock;
|
||||
rv = newMailParser->Init(serverFolder, inbox,
|
||||
fileSpec, outFileStream, nsnull);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -465,9 +482,7 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
// (or, alternatively, we got a 'From' line and
|
||||
// then the file mysteriously ended) then abort
|
||||
// parsing.
|
||||
if (numlines == 0 &&
|
||||
!*buffer &&
|
||||
spoolfile->eof()) {
|
||||
if (numlines == 0 && !*buffer && spoolfile->eof()) {
|
||||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr, "*** Utterly empty spool file\n");
|
||||
#endif
|
||||
|
@ -476,15 +491,12 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
|
||||
PL_strcpy(&buffer[PL_strlen(buffer)], MSG_LINEBREAK);
|
||||
|
||||
// fprintf(stderr, "%d: %s", numlines, buffer);
|
||||
|
||||
newMailParser->HandleLine(buffer, PL_strlen(buffer));
|
||||
*outFileStream << buffer;
|
||||
|
||||
numlines++;
|
||||
|
||||
if (numlines == 1 &&
|
||||
!spoolfile->eof()) {
|
||||
if (numlines == 1 && !spoolfile->eof()) {
|
||||
PL_strcpy(buffer, "X-Mozilla-Status: 8000"
|
||||
MSG_LINEBREAK);
|
||||
newMailParser->HandleLine(buffer,
|
||||
|
@ -510,13 +522,8 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
outFileStream = 0;
|
||||
|
||||
// truncate the spool file here.
|
||||
nsFileSpec * filespecForTrunc =
|
||||
new nsFileSpec(wholeboxname.get());
|
||||
if (filespecForTrunc) {
|
||||
filespecForTrunc->Truncate(0);
|
||||
delete filespecForTrunc;
|
||||
filespecForTrunc = nsnull;
|
||||
}
|
||||
nsFileSpec filespecForTrunc(wholeboxname.get());
|
||||
filespecForTrunc.Truncate(0);
|
||||
if (spoolfile->is_open())
|
||||
spoolfile->close();
|
||||
delete spoolfile;
|
||||
|
@ -524,19 +531,11 @@ nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow,
|
|||
|
||||
freebuff_and_unlock:
|
||||
PR_Free(buffer);
|
||||
}
|
||||
|
||||
YieldSpoolLock(wholeboxname.get());
|
||||
}
|
||||
|
||||
in_server->SetServerBusy(PR_FALSE);
|
||||
|
||||
} else {
|
||||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr, "*** NONONO get:noserv\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr, "*** YEAHYEAHYEAH get, %s\n",
|
||||
NS_FAILED(rv) ? "MISERABLE FAILURE" :
|
||||
|
@ -616,11 +615,6 @@ NS_IMETHODIMP
|
|||
nsMovemailService::GetRequiresUsername(PRBool *aRequiresUsername)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRequiresUsername);
|
||||
|
||||
#ifdef MOVEMAIL_DEBUG
|
||||
fprintf(stderr, "XXX Yah, got asked for info\n");
|
||||
#endif
|
||||
|
||||
*aRequiresUsername = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "nsIMovemailService.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIMsgProtocolInfo.h"
|
||||
#include "nsIMsgStringService.h"
|
||||
#include "nsIMsgWindow.h"
|
||||
|
||||
class nsParseNewMailState;
|
||||
class nsIFolder;
|
||||
|
@ -57,10 +59,14 @@ public:
|
|||
virtual ~nsMovemailService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
// NS_DECL_ISUbleh
|
||||
NS_DECL_NSIMOVEMAILSERVICE
|
||||
NS_DECL_NSIMSGPROTOCOLINFO
|
||||
|
||||
private:
|
||||
void Error(PRInt32 errorCode, const PRUnichar **params, PRUint32 length);
|
||||
|
||||
nsCOMPtr<nsIMsgStringService> mStringService;
|
||||
nsCOMPtr<nsIMsgWindow> mMsgWindow;
|
||||
};
|
||||
|
||||
#endif /* nsMovemailService_h___ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче