2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-04-21 20:17:23 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-04-21 20:17:23 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-04-21 20:17:23 +00:00
|
|
|
*
|
1999-11-06 03:43:54 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:43:54 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2000-02-06 03:18:27 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-04-21 20:17:23 +00:00
|
|
|
|
1999-08-07 02:30:11 +00:00
|
|
|
#include "msgCore.h"
|
|
|
|
#include "nsIMsgHdr.h"
|
1999-04-21 20:17:23 +00:00
|
|
|
#include "nsMsgUtils.h"
|
|
|
|
#include "nsString.h"
|
2001-09-29 08:28:41 +00:00
|
|
|
#include "nsReadableUtils.h"
|
1999-04-21 20:17:23 +00:00
|
|
|
#include "nsFileSpec.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsEscape.h"
|
1999-04-21 20:17:23 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-04-29 01:37:40 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-09-17 23:17:03 +00:00
|
|
|
#include "nsIImapUrl.h"
|
|
|
|
#include "nsIMailboxUrl.h"
|
|
|
|
#include "nsINntpUrl.h"
|
|
|
|
#include "nsMsgNewsCID.h"
|
|
|
|
#include "nsMsgLocalCID.h"
|
|
|
|
#include "nsMsgBaseCID.h"
|
|
|
|
#include "nsMsgImapCID.h"
|
2000-09-22 23:58:19 +00:00
|
|
|
#include "nsMsgI18N.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "prprf.h"
|
2001-07-06 21:16:32 +00:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIIOService.h"
|
2002-01-29 21:38:16 +00:00
|
|
|
#include "nsIRDFService.h"
|
2002-03-08 20:13:23 +00:00
|
|
|
#include "nsIMimeConverter.h"
|
|
|
|
#include "nsMsgMimeCID.h"
|
2002-05-21 20:44:46 +00:00
|
|
|
#include "nsICategoryManager.h"
|
2002-07-18 05:09:10 +00:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2002-10-04 22:32:15 +00:00
|
|
|
#include "nsISpamSettings.h"
|
|
|
|
|
1999-09-17 23:17:03 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
|
|
|
|
static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID);
|
|
|
|
static NS_DEFINE_CID(kCNntpUrlCID, NS_NNTPURL_CID);
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2002-05-21 20:44:46 +00:00
|
|
|
#define NS_PASSWORDMANAGER_CATEGORY "passwordmanager"
|
|
|
|
static PRBool gInitPasswordManager = PR_FALSE;
|
|
|
|
|
2001-10-06 06:35:32 +00:00
|
|
|
nsresult GetMessageServiceContractIDForURI(const char *uri, nsCString &contractID)
|
1999-04-21 20:17:23 +00:00
|
|
|
{
|
2001-10-06 06:35:32 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
//Find protocol
|
|
|
|
nsCAutoString uriStr(uri);
|
|
|
|
PRInt32 pos = uriStr.FindChar(':');
|
|
|
|
if(pos == kNotFound)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2001-10-06 06:35:32 +00:00
|
|
|
nsCAutoString protocol;
|
|
|
|
uriStr.Left(protocol, pos);
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2001-10-06 06:35:32 +00:00
|
|
|
//Build message service contractid
|
|
|
|
contractID = "@mozilla.org/messenger/messageservice;1?type=";
|
|
|
|
contractID += protocol.get();
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2001-10-06 06:35:32 +00:00
|
|
|
return rv;
|
1999-04-21 20:17:23 +00:00
|
|
|
}
|
|
|
|
|
2001-11-03 04:42:19 +00:00
|
|
|
nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **aMessageService)
|
1999-04-21 20:17:23 +00:00
|
|
|
{
|
2002-09-12 03:59:14 +00:00
|
|
|
nsresult rv;
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2002-01-08 03:19:10 +00:00
|
|
|
nsCAutoString contractID;
|
2002-09-12 03:59:14 +00:00
|
|
|
rv = GetMessageServiceContractIDForURI(uri, contractID);
|
2001-11-03 04:42:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2001-11-03 04:42:19 +00:00
|
|
|
nsCOMPtr <nsIMsgMessageService> msgService = do_GetService(contractID.get(), &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
1999-04-21 20:17:23 +00:00
|
|
|
|
2002-01-08 03:19:10 +00:00
|
|
|
NS_IF_ADDREF(*aMessageService = msgService);
|
2002-09-12 03:59:14 +00:00
|
|
|
return rv;
|
1999-04-21 20:17:23 +00:00
|
|
|
}
|
1999-04-24 20:37:00 +00:00
|
|
|
|
2001-03-17 01:59:34 +00:00
|
|
|
nsresult GetMsgDBHdrFromURI(const char *uri, nsIMsgDBHdr **msgHdr)
|
|
|
|
{
|
|
|
|
nsCOMPtr <nsIMsgMessageService> msgMessageService;
|
|
|
|
nsresult rv = GetMessageServiceFromURI(uri, getter_AddRefs(msgMessageService));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
if (!msgMessageService) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return msgMessageService->MessageURIToMsgHdr(uri, msgHdr);
|
|
|
|
}
|
1999-04-24 20:37:00 +00:00
|
|
|
|
1999-09-17 23:17:03 +00:00
|
|
|
nsresult CreateStartupUrl(char *uri, nsIURI** aUrl)
|
|
|
|
{
|
2001-11-18 23:38:52 +00:00
|
|
|
nsresult rv = NS_ERROR_NULL_POINTER;
|
|
|
|
if (!uri || !*uri || !aUrl) return rv;
|
|
|
|
*aUrl = nsnull;
|
|
|
|
|
|
|
|
// XXX fix this, so that base doesn't depend on imap, local or news.
|
|
|
|
// we can't do NS_NewURI(uri, aUrl), because these are imap-message://, mailbox-message://, news-message:// uris.
|
|
|
|
// I think we should do something like GetMessageServiceFromURI() to get the service, and then have the service create the
|
|
|
|
// appropriate nsI*Url, and then QI to nsIURI, and return it.
|
|
|
|
// see bug #110689
|
|
|
|
if (PL_strncasecmp(uri, "imap", 4) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImapUrl> imapUrl = do_CreateInstance(kImapUrlCID, &rv);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && imapUrl)
|
|
|
|
rv = imapUrl->QueryInterface(NS_GET_IID(nsIURI),
|
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
else if (PL_strncasecmp(uri, "mailbox", 7) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMailboxUrl> mailboxUrl = do_CreateInstance(kCMailboxUrl, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && mailboxUrl)
|
|
|
|
rv = mailboxUrl->QueryInterface(NS_GET_IID(nsIURI),
|
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
else if (PL_strncasecmp(uri, "news", 4) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsINntpUrl> nntpUrl = do_CreateInstance(kCNntpUrlCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && nntpUrl)
|
|
|
|
rv = nntpUrl->QueryInterface(NS_GET_IID(nsIURI),
|
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
if (*aUrl)
|
2002-03-06 07:48:55 +00:00
|
|
|
(*aUrl)->SetSpec(nsDependentCString(uri));
|
2001-11-18 23:38:52 +00:00
|
|
|
return rv;
|
1999-09-17 23:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-05-10 21:06:39 +00:00
|
|
|
// Where should this live? It's a utility used to convert a string priority, e.g., "High, Low, Normal" to an enum.
|
|
|
|
// Perhaps we should have an interface that groups together all these utilities...
|
2000-05-01 23:19:46 +00:00
|
|
|
nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriorityValue *outPriority)
|
1999-05-10 21:06:39 +00:00
|
|
|
{
|
|
|
|
if (!outPriority)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-05-01 23:19:46 +00:00
|
|
|
nsMsgPriorityValue retPriority = nsMsgPriority::normal;
|
1999-05-10 21:06:39 +00:00
|
|
|
|
|
|
|
if (PL_strcasestr(priority, "Normal") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::normal;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "Lowest") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::lowest;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "Highest") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::highest;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "High") != NULL ||
|
|
|
|
PL_strcasestr(priority, "Urgent") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::high;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "Low") != NULL ||
|
|
|
|
PL_strcasestr(priority, "Non-urgent") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::low;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "1") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::highest;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "2") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::high;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "3") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::normal;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "4") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::low;
|
1999-05-10 21:06:39 +00:00
|
|
|
else if (PL_strcasestr(priority, "5") != NULL)
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::lowest;
|
1999-05-10 21:06:39 +00:00
|
|
|
else
|
2000-05-01 23:19:46 +00:00
|
|
|
retPriority = nsMsgPriority::normal;
|
1999-05-10 21:06:39 +00:00
|
|
|
*outPriority = retPriority;
|
|
|
|
return NS_OK;
|
|
|
|
//return nsMsgNoPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-01 23:19:46 +00:00
|
|
|
nsresult NS_MsgGetUntranslatedPriorityName (nsMsgPriorityValue p, nsString *outName)
|
1999-05-12 03:16:20 +00:00
|
|
|
{
|
|
|
|
if (!outName)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
switch (p)
|
|
|
|
{
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::notSet:
|
|
|
|
case nsMsgPriority::none:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("None"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::lowest:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("Lowest"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::low:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("Low"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::normal:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("Normal"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::high:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("High"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::highest:
|
2001-12-16 11:58:03 +00:00
|
|
|
outName->Assign(NS_LITERAL_STRING("Highest"));
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ASSERTION(PR_FALSE, "invalid priority value");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-08 05:08:31 +00:00
|
|
|
/* this used to be XP_StringHash2 from xp_hash.c */
|
|
|
|
/* phong's linear congruential hash */
|
|
|
|
static PRUint32 StringHash(const char *ubuf)
|
|
|
|
{
|
|
|
|
unsigned char * buf = (unsigned char*) ubuf;
|
|
|
|
PRUint32 h=1;
|
|
|
|
while(*buf) {
|
|
|
|
h = 0x63c63cd9*h + 0x9c39c33d + (int32)*buf;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
1999-08-05 04:28:28 +00:00
|
|
|
nsresult NS_MsgHashIfNecessary(nsCAutoString &name)
|
1999-06-08 05:08:31 +00:00
|
|
|
{
|
2001-01-24 00:50:14 +00:00
|
|
|
#if defined(XP_MAC)
|
1999-06-08 18:33:30 +00:00
|
|
|
const PRUint32 MAX_LEN = 25;
|
2001-05-31 05:26:08 +00:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_BEOS)
|
|
|
|
const PRUint32 MAX_LEN = 55;
|
|
|
|
#elif defined(XP_WIN32)
|
1999-06-08 05:08:31 +00:00
|
|
|
const PRUint32 MAX_LEN = 55;
|
2001-05-31 05:26:08 +00:00
|
|
|
#elif defined(XP_OS2)
|
2001-10-01 18:44:22 +00:00
|
|
|
const PRUint32 MAX_LEN = 55;
|
1999-06-08 05:08:31 +00:00
|
|
|
#else
|
2002-02-12 03:57:39 +00:00
|
|
|
#error need_to_define_your_max_filename_length
|
1999-06-08 05:08:31 +00:00
|
|
|
#endif
|
2002-02-12 03:57:39 +00:00
|
|
|
nsCAutoString illegalChars(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS);
|
1999-08-05 04:28:28 +00:00
|
|
|
nsCAutoString str(name);
|
1999-06-08 05:08:31 +00:00
|
|
|
|
2001-05-31 05:26:08 +00:00
|
|
|
// Given a filename, make it safe for filesystem
|
|
|
|
// certain filenames require hashing because they
|
|
|
|
// are too long or contain illegal characters
|
|
|
|
PRInt32 illegalCharacterIndex = str.FindCharInSet(illegalChars);
|
1999-06-08 05:08:31 +00:00
|
|
|
char hashedname[MAX_LEN + 1];
|
2001-05-31 05:26:08 +00:00
|
|
|
if (illegalCharacterIndex == kNotFound)
|
|
|
|
{
|
|
|
|
// no illegal chars, it's just too long
|
|
|
|
// keep the initial part of the string, but hash to make it fit
|
|
|
|
if (str.Length() > MAX_LEN)
|
|
|
|
{
|
|
|
|
PL_strncpy(hashedname, str.get(), MAX_LEN + 1);
|
|
|
|
PR_snprintf(hashedname + MAX_LEN - 8, 9, "%08lx",
|
|
|
|
(unsigned long) StringHash(str.get()));
|
|
|
|
name = hashedname;
|
|
|
|
}
|
1999-06-08 05:08:31 +00:00
|
|
|
}
|
2001-05-31 05:26:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// found illegal chars, hash the whole thing
|
|
|
|
// if we do substitution, then hash, two strings
|
|
|
|
// could hash to the same value.
|
|
|
|
// for example, on mac: "foo__bar", "foo:_bar", "foo::bar"
|
|
|
|
// would map to "foo_bar". this way, all three will map to
|
|
|
|
// different values
|
|
|
|
PR_snprintf(hashedname, 9, "%08lx",
|
2001-03-02 09:26:57 +00:00
|
|
|
(unsigned long) StringHash(str.get()));
|
2001-05-31 05:26:08 +00:00
|
|
|
name = hashedname;
|
1999-06-08 05:08:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-26 20:46:39 +00:00
|
|
|
nsresult NS_MsgCreatePathStringFromFolderURI(const char *folderURI, nsCString& pathString)
|
|
|
|
{
|
2000-09-22 23:58:19 +00:00
|
|
|
// A file name has to be in native charset, convert from UTF-8.
|
|
|
|
nsCAutoString oldPath;
|
2002-01-09 22:37:28 +00:00
|
|
|
if (nsCRT::IsAscii(folderURI))
|
|
|
|
oldPath.Assign(folderURI);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *nativeString = nsnull;
|
|
|
|
nsresult rv = ConvertFromUnicode(nsMsgI18NFileSystemCharset(),
|
|
|
|
nsAutoString(NS_ConvertUTF8toUCS2(folderURI)), &nativeString);
|
|
|
|
if (NS_SUCCEEDED(rv) && nativeString && nativeString[0])
|
|
|
|
oldPath.Assign(nativeString);
|
|
|
|
else
|
|
|
|
oldPath.Assign(folderURI);
|
|
|
|
PR_FREEIF(nativeString);
|
|
|
|
}
|
2000-09-22 23:58:19 +00:00
|
|
|
|
2000-02-26 20:46:39 +00:00
|
|
|
nsCAutoString pathPiece;
|
|
|
|
|
|
|
|
PRInt32 startSlashPos = oldPath.FindChar('/');
|
|
|
|
PRInt32 endSlashPos = (startSlashPos >= 0)
|
2002-02-01 01:53:09 +00:00
|
|
|
? oldPath.FindChar('/', startSlashPos + 1) - 1 : oldPath.Length() - 1;
|
2002-04-30 16:43:26 +00:00
|
|
|
if (endSlashPos < 0)
|
2000-02-26 20:46:39 +00:00
|
|
|
endSlashPos = oldPath.Length();
|
|
|
|
// trick to make sure we only add the path to the first n-1 folders
|
|
|
|
PRBool haveFirst=PR_FALSE;
|
|
|
|
while (startSlashPos != -1) {
|
|
|
|
oldPath.Mid(pathPiece, startSlashPos + 1, endSlashPos - startSlashPos);
|
|
|
|
// skip leading '/' (and other // style things)
|
|
|
|
if (pathPiece.Length() > 0) {
|
|
|
|
|
|
|
|
// add .sbd onto the previous path
|
|
|
|
if (haveFirst) {
|
|
|
|
pathString+=".sbd";
|
|
|
|
pathString += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_MsgHashIfNecessary(pathPiece);
|
|
|
|
pathString += pathPiece;
|
|
|
|
haveFirst=PR_TRUE;
|
|
|
|
}
|
|
|
|
// look for the next slash
|
|
|
|
startSlashPos = endSlashPos + 1;
|
|
|
|
|
|
|
|
endSlashPos = (startSlashPos >= 0)
|
2002-02-01 01:53:09 +00:00
|
|
|
? oldPath.FindChar('/', startSlashPos + 1) - 1: oldPath.Length() - 1;
|
2002-04-30 16:43:26 +00:00
|
|
|
if (endSlashPos < 0)
|
2000-02-26 20:46:39 +00:00
|
|
|
endSlashPos = oldPath.Length();
|
|
|
|
|
2002-04-30 16:43:26 +00:00
|
|
|
if (startSlashPos >= endSlashPos)
|
2000-02-26 20:46:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-03-17 01:59:34 +00:00
|
|
|
|
|
|
|
/* Given a string and a length, removes any "Re:" strings from the front.
|
|
|
|
It also deals with that dumbass "Re[2]:" thing that some losing mailers do.
|
|
|
|
|
|
|
|
Returns PR_TRUE if it made a change, PR_FALSE otherwise.
|
|
|
|
|
|
|
|
The string is not altered: the pointer to its head is merely advanced,
|
|
|
|
and the length correspondingly decreased.
|
|
|
|
*/
|
2002-04-23 02:18:19 +00:00
|
|
|
PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP, char **modifiedSubject)
|
2001-03-17 01:59:34 +00:00
|
|
|
{
|
|
|
|
const char *s, *s_end;
|
|
|
|
const char *last;
|
|
|
|
PRUint32 L;
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
NS_ASSERTION(stringP, "bad null param");
|
|
|
|
if (!stringP) return PR_FALSE;
|
2002-03-08 20:13:23 +00:00
|
|
|
|
|
|
|
// decode the string
|
|
|
|
nsXPIDLCString decodedString;
|
|
|
|
nsCOMPtr<nsIMimeConverter> mimeConverter;
|
|
|
|
nsresult rv;
|
2002-04-23 02:18:19 +00:00
|
|
|
// we cannot strip "Re:" for MIME encoded subject without modifying the original
|
|
|
|
if (modifiedSubject && strstr(*stringP, "=?"))
|
2002-03-08 20:13:23 +00:00
|
|
|
{
|
2002-09-27 09:32:06 +00:00
|
|
|
mimeConverter = do_GetService(NS_MIME_CONVERTER_CONTRACTID, &rv);
|
2002-03-08 20:13:23 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = mimeConverter->DecodeMimeHeader(*stringP, getter_Copies(decodedString));
|
|
|
|
}
|
|
|
|
|
|
|
|
s = decodedString ? decodedString.get() : *stringP;
|
2002-02-19 08:42:48 +00:00
|
|
|
L = lengthP ? *lengthP : strlen(s);
|
2001-03-17 01:59:34 +00:00
|
|
|
|
|
|
|
s_end = s + L;
|
|
|
|
last = s;
|
|
|
|
|
|
|
|
AGAIN:
|
|
|
|
|
2001-04-27 00:22:18 +00:00
|
|
|
while (s < s_end && IS_SPACE(*s))
|
2001-03-17 01:59:34 +00:00
|
|
|
s++;
|
|
|
|
|
|
|
|
if (s < (s_end-2) &&
|
|
|
|
(s[0] == 'r' || s[0] == 'R') &&
|
|
|
|
(s[1] == 'e' || s[1] == 'E'))
|
|
|
|
{
|
|
|
|
if (s[2] == ':')
|
|
|
|
{
|
|
|
|
s = s+3; /* Skip over "Re:" */
|
|
|
|
result = PR_TRUE; /* Yes, we stripped it. */
|
|
|
|
goto AGAIN; /* Skip whitespace and try again. */
|
|
|
|
}
|
|
|
|
else if (s[2] == '[' || s[2] == '(')
|
|
|
|
{
|
|
|
|
const char *s2 = s+3; /* Skip over "Re[" */
|
|
|
|
|
|
|
|
/* Skip forward over digits after the "[". */
|
2001-04-27 00:22:18 +00:00
|
|
|
while (s2 < (s_end-2) && IS_DIGIT(*s2))
|
2001-03-17 01:59:34 +00:00
|
|
|
s2++;
|
|
|
|
|
|
|
|
/* Now ensure that the following thing is "]:"
|
|
|
|
Only if it is do we alter `s'.
|
|
|
|
*/
|
|
|
|
if ((s2[0] == ']' || s2[0] == ')') && s2[1] == ':')
|
|
|
|
{
|
|
|
|
s = s2+2; /* Skip over "]:" */
|
|
|
|
result = PR_TRUE; /* Yes, we stripped it. */
|
|
|
|
goto AGAIN; /* Skip whitespace and try again. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-08 20:13:23 +00:00
|
|
|
if (decodedString)
|
|
|
|
{
|
|
|
|
// encode the string back if any modification is made
|
|
|
|
if (s != decodedString.get())
|
|
|
|
{
|
|
|
|
// extract between "=?" and "?"
|
|
|
|
// e.g. =?ISO-2022-JP?
|
2002-03-12 23:49:23 +00:00
|
|
|
const char *p1 = strstr(*stringP, "=?");
|
2002-03-08 20:13:23 +00:00
|
|
|
if (p1)
|
|
|
|
{
|
|
|
|
p1 += sizeof("=?")-1; // skip "=?"
|
2002-03-12 23:49:23 +00:00
|
|
|
const char *p2 = strchr(p1, '?'); // then search for '?'
|
2002-03-08 20:13:23 +00:00
|
|
|
if (p2)
|
|
|
|
{
|
|
|
|
char charset[kMAX_CSNAME] = "";
|
|
|
|
if (kMAX_CSNAME >= (p2 - p1))
|
|
|
|
strncpy(charset, p1, p2 - p1);
|
|
|
|
rv = mimeConverter->EncodeMimePartIIStr_UTF8(s, PR_FALSE, charset, sizeof("Subject:"),
|
2002-04-23 02:18:19 +00:00
|
|
|
kMIME_ENCODED_WORD_SIZE, modifiedSubject);
|
2002-03-08 20:13:23 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
s = *stringP; // no modification, set the original encoded string
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-17 01:59:34 +00:00
|
|
|
/* Decrease length by difference between current ptr and original ptr.
|
|
|
|
Then store the current ptr back into the caller. */
|
|
|
|
if (lengthP)
|
|
|
|
*lengthP -= (s - (*stringP));
|
|
|
|
*stringP = s;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-04-27 00:22:18 +00:00
|
|
|
|
|
|
|
/* Very similar to strdup except it free's too
|
|
|
|
*/
|
|
|
|
char * NS_MsgSACopy (char **destination, const char *source)
|
|
|
|
{
|
|
|
|
if(*destination)
|
|
|
|
{
|
|
|
|
PR_Free(*destination);
|
|
|
|
*destination = 0;
|
|
|
|
}
|
|
|
|
if (! source)
|
|
|
|
*destination = nsnull;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*destination = (char *) PR_Malloc (PL_strlen(source) + 1);
|
|
|
|
if (*destination == nsnull)
|
|
|
|
return(nsnull);
|
|
|
|
|
|
|
|
PL_strcpy (*destination, source);
|
|
|
|
}
|
|
|
|
return *destination;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Again like strdup but it concatinates and free's and uses Realloc
|
|
|
|
*/
|
|
|
|
char * NS_MsgSACat (char **destination, const char *source)
|
|
|
|
{
|
|
|
|
if (source && *source)
|
|
|
|
if (*destination)
|
|
|
|
{
|
|
|
|
int length = PL_strlen (*destination);
|
|
|
|
*destination = (char *) PR_Realloc (*destination, length + PL_strlen(source) + 1);
|
|
|
|
if (*destination == nsnull)
|
|
|
|
return(nsnull);
|
|
|
|
|
|
|
|
PL_strcpy (*destination + length, source);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*destination = (char *) PR_Malloc (PL_strlen(source) + 1);
|
|
|
|
if (*destination == nsnull)
|
|
|
|
return(nsnull);
|
|
|
|
|
|
|
|
PL_strcpy (*destination, source);
|
|
|
|
}
|
|
|
|
return *destination;
|
|
|
|
}
|
|
|
|
|
2001-05-10 07:26:30 +00:00
|
|
|
nsresult NS_MsgEscapeEncodeURLPath(const PRUnichar *str, char **result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(str);
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
|
|
|
|
*result = nsEscape(NS_ConvertUCS2toUTF8(str).get(), url_Path);
|
|
|
|
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_MsgDecodeUnescapeURLPath(const char *path, PRUnichar **result)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(path);
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
|
|
|
|
char *unescapedName = nsCRT::strdup(path);
|
|
|
|
if (!unescapedName) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsUnescape(unescapedName);
|
|
|
|
nsAutoString resultStr;
|
|
|
|
resultStr = NS_ConvertUTF8toUCS2(unescapedName);
|
2001-09-29 08:28:41 +00:00
|
|
|
*result = ToNewUnicode(resultStr);
|
2001-05-10 07:26:30 +00:00
|
|
|
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-07-06 21:16:32 +00:00
|
|
|
|
|
|
|
PRBool WeAreOffline()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool offline = PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr <nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && ioService)
|
|
|
|
ioService->GetOffline(&offline);
|
|
|
|
|
|
|
|
return offline;
|
|
|
|
}
|
2002-01-29 21:38:16 +00:00
|
|
|
|
2002-10-04 22:32:15 +00:00
|
|
|
nsresult GetExistingFolder(const char *aFolderURI, nsIMsgFolder **aFolder)
|
2002-01-29 21:38:16 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIRDFService> rdf(do_GetService("@mozilla.org/rdf/rdf-service;1", &rv));
|
2002-10-04 22:32:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-29 21:38:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
rv = rdf->GetResource(aFolderURI, getter_AddRefs(resource));
|
2002-10-04 22:32:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-29 21:38:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr <nsIMsgFolder> thisFolder;
|
|
|
|
thisFolder = do_QueryInterface(resource, &rv);
|
2002-10-04 22:32:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-29 21:38:16 +00:00
|
|
|
|
|
|
|
// Parent doesn't exist means that this folder doesn't exist.
|
|
|
|
nsCOMPtr<nsIFolder> parentFolder;
|
|
|
|
rv = thisFolder->GetParent(getter_AddRefs(parentFolder));
|
2002-10-04 22:32:15 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && parentFolder)
|
|
|
|
NS_ADDREF(*aFolder = thisFolder);
|
|
|
|
return rv;
|
2002-01-29 21:38:16 +00:00
|
|
|
}
|
2002-02-01 02:36:58 +00:00
|
|
|
|
|
|
|
PRBool IsAFromSpaceLine(char *start, const char *end)
|
|
|
|
{
|
|
|
|
nsresult rv = PR_FALSE;
|
|
|
|
while ((start < end) && (*start == '>'))
|
|
|
|
start++;
|
|
|
|
// If the leading '>'s are followed by an 'F' then we have a possible case here.
|
|
|
|
if ( (*start == 'F') && (end-start > 4) && !strncmp(start, "From ", 5) )
|
|
|
|
rv = PR_TRUE;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// This function finds all lines starting with "From " or "From " preceeding
|
|
|
|
// with one or more '>' (ie, ">From", ">>From", etc) in the input buffer
|
|
|
|
// (between 'start' and 'end') and prefix them with a ">" .
|
|
|
|
//
|
|
|
|
nsresult EscapeFromSpaceLine(nsIFileSpec *pDst, char *start, const char *end)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
char *pChar;
|
|
|
|
PRInt32 written;
|
|
|
|
|
|
|
|
pChar = start;
|
|
|
|
while (start < end)
|
|
|
|
{
|
|
|
|
while ((pChar < end) && (*pChar != nsCRT::CR) && (*(pChar+1) != nsCRT::LF))
|
|
|
|
pChar++;
|
|
|
|
|
|
|
|
if (pChar < end)
|
|
|
|
{
|
|
|
|
// Found a line so check if it's a qualified "From " line.
|
|
|
|
if (IsAFromSpaceLine(start, pChar))
|
|
|
|
rv = pDst->Write(">", 1, &written);
|
|
|
|
|
|
|
|
rv = pDst->Write(start, pChar-start+2, &written);
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
pChar += 2;
|
|
|
|
start = pChar;
|
|
|
|
}
|
|
|
|
else if (start < end)
|
|
|
|
{
|
|
|
|
// Check and flush out the remaining data and we're done.
|
|
|
|
if (IsAFromSpaceLine(start, end))
|
|
|
|
rv = pDst->Write(">", 1, &written);
|
|
|
|
rv = pDst->Write(start, end-start, &written);
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-21 20:44:46 +00:00
|
|
|
|
|
|
|
nsresult CreateServicesForPasswordManager()
|
|
|
|
{
|
|
|
|
if (!gInitPasswordManager)
|
|
|
|
{
|
|
|
|
// Initialize the password manager category
|
|
|
|
gInitPasswordManager = PR_TRUE;
|
|
|
|
return NS_CreateServicesFromCategory(NS_PASSWORDMANAGER_CATEGORY,
|
|
|
|
nsnull,
|
|
|
|
NS_PASSWORDMANAGER_CATEGORY);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-10-04 22:32:15 +00:00
|
|
|
|
2002-09-11 02:09:50 +00:00
|
|
|
nsresult IsRFC822HeaderFieldName(const char *aHdr, PRBool *aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHdr);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
PRUint32 length = strlen(aHdr);
|
|
|
|
for(PRUint32 i=0; i<length; i++)
|
|
|
|
{
|
|
|
|
char c = aHdr[i];
|
|
|
|
if ( c < '!' || c == ':' || c > '~')
|
|
|
|
{
|
|
|
|
*aResult = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aResult = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|