1999-04-21 20:17:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:43:54 +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
|
|
|
*
|
1999-11-06 03:43:54 +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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-04-21 20:17:23 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:43:54 +00:00
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2000-02-06 03:18:27 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
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"
|
|
|
|
#include "nsFileSpec.h"
|
|
|
|
#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"
|
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
|
|
|
|
1999-07-19 22:40:41 +00:00
|
|
|
#if defined(DEBUG_sspitzer_) || defined(DEBUG_seth_)
|
1999-07-19 20:03:10 +00:00
|
|
|
#define DEBUG_NS_MsgHashIfNecessary 1
|
1999-07-17 19:08:20 +00:00
|
|
|
#endif
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
nsresult GetMessageServiceContractIDForURI(const char *uri, nsString &contractID)
|
1999-04-21 20:17:23 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
//Find protocol
|
2000-04-22 08:43:34 +00:00
|
|
|
nsAutoString uriStr; uriStr.AssignWithConversion(uri);
|
1999-07-26 01:01:10 +00:00
|
|
|
PRInt32 pos = uriStr.FindChar(':');
|
1999-04-21 20:17:23 +00:00
|
|
|
if(pos == -1)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsString protocol;
|
|
|
|
uriStr.Left(protocol, pos);
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
//Build message service contractid
|
|
|
|
contractID.AssignWithConversion("@mozilla.org/messenger/messageservice;1?type=");
|
|
|
|
contractID += protocol;
|
1999-04-21 20:17:23 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **messageService)
|
|
|
|
{
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
nsAutoString contractID;
|
1999-04-21 20:17:23 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = GetMessageServiceContractIDForURI(uri, contractID);
|
1999-04-21 20:17:23 +00:00
|
|
|
|
|
|
|
if(NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
nsCAutoString contractidC;
|
|
|
|
contractidC.AssignWithConversion(contractID);
|
|
|
|
rv = nsServiceManager::GetService((const char *) contractidC, NS_GET_IID(nsIMsgMessageService),
|
1999-04-21 20:17:23 +00:00
|
|
|
(nsISupports**)messageService, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult ReleaseMessageServiceFromURI(const char *uri, nsIMsgMessageService *messageService)
|
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
nsAutoString contractID;
|
1999-04-21 20:17:23 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2000-09-13 23:57:52 +00:00
|
|
|
rv = GetMessageServiceContractIDForURI(uri, contractID);
|
1999-04-21 20:17:23 +00:00
|
|
|
if(NS_SUCCEEDED(rv))
|
2000-04-26 01:13:55 +00:00
|
|
|
{
|
2000-09-13 23:57:52 +00:00
|
|
|
nsCAutoString contractidC;
|
|
|
|
contractidC.AssignWithConversion(contractID);
|
|
|
|
rv = nsServiceManager::ReleaseService(contractidC, messageService);
|
2000-04-26 01:13:55 +00:00
|
|
|
}
|
1999-04-21 20:17:23 +00:00
|
|
|
return rv;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_NULL_POINTER;
|
|
|
|
if (!uri || !*uri || !aUrl) return rv;
|
|
|
|
*aUrl = nsnull;
|
|
|
|
if (PL_strncasecmp(uri, "imap", 4) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImapUrl> imapUrl;
|
|
|
|
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull,
|
2000-02-06 03:18:27 +00:00
|
|
|
NS_GET_IID(nsIImapUrl),
|
1999-09-17 23:17:03 +00:00
|
|
|
getter_AddRefs(imapUrl));
|
|
|
|
if (NS_SUCCEEDED(rv) && imapUrl)
|
2000-02-06 03:18:27 +00:00
|
|
|
rv = imapUrl->QueryInterface(NS_GET_IID(nsIURI),
|
1999-09-17 23:17:03 +00:00
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
else if (PL_strncasecmp(uri, "mailbox", 7) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMailboxUrl> mailboxUrl;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCMailboxUrl, nsnull,
|
2000-02-06 03:18:27 +00:00
|
|
|
NS_GET_IID(nsIMailboxUrl),
|
1999-09-17 23:17:03 +00:00
|
|
|
getter_AddRefs(mailboxUrl));
|
|
|
|
if (NS_SUCCEEDED(rv) && mailboxUrl)
|
2000-02-06 03:18:27 +00:00
|
|
|
rv = mailboxUrl->QueryInterface(NS_GET_IID(nsIURI),
|
1999-09-17 23:17:03 +00:00
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
else if (PL_strncasecmp(uri, "news", 4) == 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsINntpUrl> nntpUrl;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCNntpUrlCID, nsnull,
|
2000-02-06 03:18:27 +00:00
|
|
|
NS_GET_IID(nsINntpUrl),
|
1999-09-17 23:17:03 +00:00
|
|
|
getter_AddRefs(nntpUrl));
|
|
|
|
if (NS_SUCCEEDED(rv) && nntpUrl)
|
2000-02-06 03:18:27 +00:00
|
|
|
rv = nntpUrl->QueryInterface(NS_GET_IID(nsIURI),
|
1999-09-17 23:17:03 +00:00
|
|
|
(void**) aUrl);
|
|
|
|
}
|
|
|
|
if (*aUrl)
|
|
|
|
(*aUrl)->SetSpec(uri);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("None");
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::lowest:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("Lowest");
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::low:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("Low");
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::normal:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("Normal");
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::high:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("High");
|
1999-05-12 03:16:20 +00:00
|
|
|
break;
|
2000-05-01 23:19:46 +00:00
|
|
|
case nsMsgPriority::highest:
|
2000-04-22 08:43:34 +00:00
|
|
|
outName->AssignWithConversion("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;
|
1999-06-29 09:19:14 +00:00
|
|
|
#elif defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
|
1999-06-08 05:08:31 +00:00
|
|
|
const PRUint32 MAX_LEN = 55;
|
|
|
|
#else
|
|
|
|
#error need_to_define_your_max_filename_length
|
|
|
|
#endif
|
1999-08-05 04:28:28 +00:00
|
|
|
nsCAutoString str(name);
|
1999-06-08 05:08:31 +00:00
|
|
|
|
1999-07-17 19:08:20 +00:00
|
|
|
#ifdef DEBUG_NS_MsgHashIfNecessary
|
2001-03-02 09:26:57 +00:00
|
|
|
printf("in: %s\n",str.get());
|
1999-06-08 05:08:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Given a name, use either that name, if it fits on our
|
|
|
|
// filesystem, or a hashified version of it, if the name is too
|
|
|
|
// long to fit.
|
|
|
|
char hashedname[MAX_LEN + 1];
|
2001-03-02 09:26:57 +00:00
|
|
|
PRBool needshash = PL_strlen(str.get()) > MAX_LEN;
|
1999-06-08 05:08:31 +00:00
|
|
|
#if defined(XP_WIN16) || defined(XP_OS2)
|
|
|
|
if (!needshash) {
|
2001-03-02 09:26:57 +00:00
|
|
|
needshash = PL_strchr(str.get(), '.') != nsnull ||
|
|
|
|
PL_strchr(str.get(), ':') != nsnull;
|
1999-06-08 05:08:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
2001-03-02 09:26:57 +00:00
|
|
|
PL_strncpy(hashedname, str.get(), MAX_LEN + 1);
|
1999-06-08 05:08:31 +00:00
|
|
|
if (needshash) {
|
|
|
|
PR_snprintf(hashedname + MAX_LEN - 8, 9, "%08lx",
|
2001-03-02 09:26:57 +00:00
|
|
|
(unsigned long) StringHash(str.get()));
|
1999-06-08 05:08:31 +00:00
|
|
|
}
|
|
|
|
name = hashedname;
|
1999-07-17 19:08:20 +00:00
|
|
|
#ifdef DEBUG_NS_MsgHashIfNecessary
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("out: %s\n",hashedname);
|
1999-06-08 05:08:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
const nsString fileCharset(nsMsgI18NFileSystemCharset());
|
|
|
|
char *nativeString;
|
|
|
|
nsresult rv = ConvertFromUnicode(fileCharset, nsAutoString(NS_ConvertUTF8toUCS2(folderURI)), &nativeString);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
oldPath.Assign(nativeString);
|
|
|
|
else
|
|
|
|
oldPath.Assign(folderURI);
|
|
|
|
PR_FREEIF(nativeString);
|
|
|
|
|
2000-02-26 20:46:39 +00:00
|
|
|
nsCAutoString pathPiece;
|
|
|
|
|
|
|
|
PRInt32 startSlashPos = oldPath.FindChar('/');
|
|
|
|
PRInt32 endSlashPos = (startSlashPos >= 0)
|
|
|
|
? oldPath.FindChar('/', PR_FALSE, startSlashPos + 1) - 1 : oldPath.Length() - 1;
|
|
|
|
if (endSlashPos == -1)
|
|
|
|
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)
|
|
|
|
? oldPath.FindChar('/', PR_FALSE, startSlashPos + 1) - 1: oldPath.Length() - 1;
|
|
|
|
if (endSlashPos == -1)
|
|
|
|
endSlashPos = oldPath.Length();
|
|
|
|
|
|
|
|
if (startSlashPos == endSlashPos)
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
PRBool NS_MsgStripRE(const char **stringP, PRUint32 *lengthP)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
s = *stringP;
|
|
|
|
L = lengthP ? *lengthP : nsCRT::strlen(s);
|
|
|
|
|
|
|
|
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. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|