nsIMsgRFC822Parser and related changes, removed old i18n functions, instead passing charset name.

This commit is contained in:
nhotta%netscape.com 1999-04-13 19:18:22 +00:00
parent 2152638ec9
commit 6d3502a293
9 changed files with 49 additions and 128 deletions

View File

@ -49,46 +49,51 @@ public:
consecutive null-terminated strings. It is up to the caller to free them.
Note that some of the strings may be zero-length.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Either of the provided pointers may be NULL if the caller is not interested
in those components.
*/
NS_IMETHOD ParseRFC822Addresses (const char *line, char **names, char **addresses, PRUint32& numAddresses) = 0;
NS_IMETHOD ParseRFC822Addresses_Intl (PRInt16 csid, const char *line, char **names, char **addresses, PRUint32& numAddresses) = 0;
NS_IMETHOD ParseRFC822Addresses (const char *charset, const char *line, char **names, char **addresses, PRUint32& numAddresses) = 0;
/* Given a string which contains a list of RFC822 addresses, returns a
comma-seperated list of just the `mailbox' portions.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must call PL_strfree on returnValue (which is allocated by the function)
*/
NS_IMETHOD ExtractRFC822AddressMailboxes (const char *line, char ** mailboxes) = 0;
NS_IMETHOD ExtractRFC822AddressMailboxes_Intl (PRInt16 csid, const char *line, char ** mailboxes) = 0;
NS_IMETHOD ExtractRFC822AddressMailboxes (const char *charset, const char *line, char ** mailboxes) = 0;
/* Given a string which contains a list of RFC822 addresses, returns a
comma-seperated list of just the `user name' portions. If any of
the addresses doesn't have a name, then the mailbox is used instead.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must PL_strfree usernames.
*/
NS_IMETHOD ExtractRFC822AddressNames (const char *line, char ** userNames) = 0;
NS_IMETHOD ExtractRFC822AddressNames_Intl (PRInt16 csid, const char *line, char ** userNames)= 0;
NS_IMETHOD ExtractRFC822AddressNames (const char *charset, const char *line, char ** userNames) = 0;
/* Like MSG_ExtractRFC822AddressNames(), but only returns the first name
in the list, if there is more than one.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must call PL_strfree on name
*/
NS_IMETHOD ExtractRFC822AddressName (const char *line, char ** name) = 0;
NS_IMETHOD ExtractRFC822AddressName_Intl (PRInt16 csid, const char *line, char ** name) = 0;
NS_IMETHOD ExtractRFC822AddressName (const char *charset, const char *line, char ** name) = 0;
/* Given a string which contains a list of RFC822 addresses, returns a new
string with the same data, but inserts missing commas, parses and reformats
it, and wraps long lines with newline-tab.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must call PL_strfree on reformattedAddress
*/
NS_IMETHOD ReformatRFC822Addresses (const char *line, char ** reformattedAddress) = 0;
NS_IMETHOD ReformatRFC822Addresses_Intl (PRInt16 csid, const char *line, char ** reformattedAddress) = 0;
NS_IMETHOD ReformatRFC822Addresses (const char *charset, const char *line, char ** reformattedAddress) = 0;
/* Returns a copy of ADDRS which may have had some addresses removed.
Addresses are removed if they are already in either ADDRS or OTHER_ADDRS.
@ -103,27 +108,28 @@ public:
contains regular expressions which also mean 'me' for the purpose of
stripping the user's email address(es) out of addrs
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must call PL_strfree on newAddress which is the return value.
*/
NS_IMETHOD RemoveDuplicateAddresses (const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newAddress) = 0;
NS_IMETHOD RemoveDuplicateAddresses_Intl (PRInt16 csid, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newAddress) = 0;
NS_IMETHOD RemoveDuplicateAddresses (const char *charset, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newAddress) = 0;
/* Given an e-mail address and a person's name, cons them together into a
single string of the form "name <address>", doing all the necessary quoting.
A new string is returned, which you must free when you're done with it.
The caller may pass nsnull for charset and it will be interpreted as "us-ascii".
Caller must call PL_strfree on fullAddress
*/
NS_IMETHOD MakeFullAddress (const char* name, const char* addr, char ** fullAddress) = 0;
NS_IMETHOD MakeFullAddress_Intl (PRInt16 csid, const char* name, const char* addr, char ** fullAddress) = 0;
NS_IMETHOD MakeFullAddress (const char *charset, const char* name, const char* addr, char ** fullAddress) = 0;
/* MSG_ParseRFC822Addresses returns quoted parsable addresses
This function removes the quoting if you want to show the
names to users. e.g. summary file, address book
*/
NS_IMETHOD UnquotePhraseOrAddr (const char *line, char** lineout) = 0;
NS_IMETHOD UnquotePhraseOrAddr_Intl (PRInt16 csid, const char *line, char** lineout) = 0;
NS_IMETHOD UnquotePhraseOrAddr (const char *charset, const char *line, char** lineout) = 0;
};

View File

@ -96,19 +96,13 @@ NS_IMPL_ADDREF(nsMsgRFC822Parser)
NS_IMPL_RELEASE(nsMsgRFC822Parser)
NS_IMPL_QUERY_INTERFACE(nsMsgRFC822Parser, nsIMsgRFC822Parser::GetIID()); /* we need to pass in the interface ID of this interface */
nsresult nsMsgRFC822Parser::ParseRFC822Addresses (const char *line, char **names, char **addresses, PRUint32& numAddresses)
nsresult nsMsgRFC822Parser::ParseRFC822Addresses (const char *charset, const char *line, char **names, char **addresses, PRUint32& numAddresses)
{
numAddresses = msg_parse_rfc822_addresses(CS_APP_DEFAULT, line, names, addresses);
return NS_OK;
}
nsresult nsMsgRFC822Parser::ParseRFC822Addresses_Intl (PRInt16 csid, const char *line, char **names, char **addresses, PRUint32& numAddresses)
{
numAddresses = msg_parse_rfc822_addresses(csid, line, names, addresses);
return NS_OK;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressMailboxes (const char *line, char ** mailboxes)
nsresult nsMsgRFC822Parser::ExtractRFC822AddressMailboxes (const char *charset, const char *line, char ** mailboxes)
{
if (mailboxes)
{
@ -119,18 +113,7 @@ nsresult nsMsgRFC822Parser::ExtractRFC822AddressMailboxes (const char *line, cha
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressMailboxes_Intl (PRInt16 csid, const char *line, char ** mailboxes)
{
if (mailboxes)
{
*mailboxes = msg_extract_rfc822_address_mailboxes(csid, line);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressNames (const char *line, char ** names)
nsresult nsMsgRFC822Parser::ExtractRFC822AddressNames (const char *charset, const char *line, char ** names)
{
if (names)
{
@ -141,18 +124,8 @@ nsresult nsMsgRFC822Parser::ExtractRFC822AddressNames (const char *line, char **
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressNames_Intl (PRInt16 csid, const char *line, char ** names)
{
if (names)
{
*names = msg_extract_rfc822_address_names(csid, line);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressName (const char *line, char ** name)
nsresult nsMsgRFC822Parser::ExtractRFC822AddressName (const char *charset, const char *line, char ** name)
{
if (name)
{
@ -163,18 +136,7 @@ nsresult nsMsgRFC822Parser::ExtractRFC822AddressName (const char *line, char **
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ExtractRFC822AddressName_Intl (PRInt16 csid, const char *line, char ** name)
{
if (name)
{
*name = msg_extract_rfc822_address_name(csid, line);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ReformatRFC822Addresses (const char *line, char ** reformattedAddress)
nsresult nsMsgRFC822Parser::ReformatRFC822Addresses (const char *charset, const char *line, char ** reformattedAddress)
{
if (reformattedAddress)
{
@ -185,18 +147,7 @@ nsresult nsMsgRFC822Parser::ReformatRFC822Addresses (const char *line, char ** r
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::ReformatRFC822Addresses_Intl (PRInt16 csid, const char *line, char ** reformattedAddress)
{
if (reformattedAddress)
{
*reformattedAddress = msg_reformat_rfc822_addresses(csid, line);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::RemoveDuplicateAddresses (const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newOutput)
nsresult nsMsgRFC822Parser::RemoveDuplicateAddresses (const char *charset, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newOutput)
{
if (newOutput)
{
@ -207,18 +158,7 @@ nsresult nsMsgRFC822Parser::RemoveDuplicateAddresses (const char *addrs, const c
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::RemoveDuplicateAddresses_Intl (PRInt16 csid, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** newOutput)
{
if (newOutput)
{
*newOutput = msg_remove_duplicate_addresses(csid, addrs, other_addrs, removeAliasesToMe);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::MakeFullAddress (const char* name, const char* addr, char ** fullAddress)
nsresult nsMsgRFC822Parser::MakeFullAddress (const char *charset, const char* name, const char* addr, char ** fullAddress)
{
if (fullAddress)
{
@ -229,29 +169,12 @@ nsresult nsMsgRFC822Parser::MakeFullAddress (const char* name, const char* addr,
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::MakeFullAddress_Intl (PRInt16 csid, const char* name, const char* addr, char ** fullAddress)
{
if (fullAddress)
{
*fullAddress = msg_make_full_address(csid, name, addr);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
nsresult nsMsgRFC822Parser::UnquotePhraseOrAddr (const char *line, char** lineout)
nsresult nsMsgRFC822Parser::UnquotePhraseOrAddr (const char *charset, const char *line, char** lineout)
{
msg_unquote_phrase_or_addr(CS_APP_DEFAULT, line, lineout);
return NS_OK;
}
nsresult nsMsgRFC822Parser::UnquotePhraseOrAddr_Intl (PRInt16 csid, const char *line, char** lineout)
{
msg_unquote_phrase_or_addr(csid, line, lineout);
return NS_OK;
}
/* this function will be used by the factory to generate an RFC-822 Parser....*/
nsresult NS_NewRFC822Parser(const nsIID &aIID, void ** aInstancePtrResult)
{

View File

@ -52,16 +52,14 @@
Either of the provided pointers may be NULL if the caller is not interested
in those components.
*/
NS_IMETHOD ParseRFC822Addresses (const char *line, char **names, char **addresses, PRUint32& numAddresses);
NS_IMETHOD ParseRFC822Addresses_Intl (PRInt16 csid, const char *line, char **names, char **addresses, PRUint32& numAddresses);
NS_IMETHOD ParseRFC822Addresses (const char *charset, const char *line, char **names, char **addresses, PRUint32& numAddresses);
/* Given a string which contains a list of RFC822 addresses, returns a
comma-seperated list of just the `mailbox' portions.
Caller must call PL_Free on mailboxes string returned by these calls.
*/
NS_IMETHOD ExtractRFC822AddressMailboxes (const char *line, char ** mailboxes);
NS_IMETHOD ExtractRFC822AddressMailboxes_Intl (PRInt16 csid, const char *line, char ** mailboxes);
NS_IMETHOD ExtractRFC822AddressMailboxes (const char *charset, const char *line, char ** mailboxes);
/* Given a string which contains a list of RFC822 addresses, returns a
@ -70,16 +68,14 @@
Caller must call PL_Free on userNames
*/
NS_IMETHOD ExtractRFC822AddressNames (const char *line, char ** userNames);
NS_IMETHOD ExtractRFC822AddressNames_Intl (PRInt16 csid, const char *line, char ** userNames);
NS_IMETHOD ExtractRFC822AddressNames (const char *charset, const char *line, char ** userNames);
/* Like MSG_ExtractRFC822AddressNames(), but only returns the first name
in the list, if there is more than one.
Caller must call PL_Free on the returned firstName string.
*/
NS_IMETHOD ExtractRFC822AddressName (const char *line, char ** firstName);
NS_IMETHOD ExtractRFC822AddressName_Intl (PRInt16 csid, const char *line, char ** firstName);
NS_IMETHOD ExtractRFC822AddressName (const char *charset, const char *line, char ** firstName);
/* Given a string which contains a list of RFC822 addresses, returns a new
string with the same data, but inserts missing commas, parses and reformats
@ -87,8 +83,7 @@
Caller must call PL_Free on the returned string
*/
NS_IMETHOD ReformatRFC822Addresses (const char *line, char ** reformattedAddress);
NS_IMETHOD ReformatRFC822Addresses_Intl (PRInt16 csid, const char *line, char ** reformattedAddress);
NS_IMETHOD ReformatRFC822Addresses (const char *charset, const char *line, char ** reformattedAddress);
/* Returns a copy of ADDRS which may have had some addresses removed.
Addresses are removed if they are already in either ADDRS or OTHER_ADDRS.
@ -105,8 +100,7 @@
Caller must call PL_Free on outString.
*/
NS_IMETHOD RemoveDuplicateAddresses (const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** outString);
NS_IMETHOD RemoveDuplicateAddresses_Intl (PRInt16 csid, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** outString);
NS_IMETHOD RemoveDuplicateAddresses (const char *charset, const char *addrs, const char *other_addrs, PRBool removeAliasesToMe, char ** outString);
/* Given an e-mail address and a person's name, cons them together into a
@ -115,15 +109,13 @@
Caller must call PL_Free on fullAddress
*/
NS_IMETHOD MakeFullAddress (const char* name, const char* addr, char ** fullAddress);
NS_IMETHOD MakeFullAddress_Intl (PRInt16 csid, const char* name, const char* addr, char ** fullAddress);
NS_IMETHOD MakeFullAddress (const char *charset, const char* name, const char* addr, char ** fullAddress);
/* MSG_ParseRFC822Addresses returns quoted parsable addresses
This function removes the quoting if you want to show the
names to users. e.g. summary file, address book
*/
NS_IMETHOD UnquotePhraseOrAddr (const char *line, char** lineout);
NS_IMETHOD UnquotePhraseOrAddr_Intl (PRInt16 csid, const char *line, char** lineout);
NS_IMETHOD UnquotePhraseOrAddr (const char *charset, const char *line, char** lineout);
private:
};

View File

@ -29,7 +29,7 @@ static NS_DEFINE_CID(kMsgRFC822ParserCID, NS_MSGRFC822PARSER_CID);
char * names = NULL;
char * addresses = NULL;
PRUint32 numAddresses = 0;
sample->ParseRFC822Addresses("Scott MacGregor <mscott@netscape.com>", &names, &addresses, numAddresses);
sample->ParseRFC822Addresses(NULL, "Scott MacGregor <mscott@netscape.com>", &names, &addresses, numAddresses);
if (names)
{
printf(names);

View File

@ -1645,7 +1645,7 @@ static char * mime_fix_header_1 (const char *string, PRBool addr_p, PRBool news_
(void **) &pRfc822);
if (NS_SUCCEEDED(rv)) {
char *n;
pRfc822->ReformatRFC822Addresses(string, &n);
pRfc822->ReformatRFC822Addresses(nsnull, string, &n);
pRfc822->Release();
if (n)
return n;

View File

@ -624,7 +624,7 @@ PRInt32 nsSmtpProtocol::SendHeloResponse(nsIInputStream * inputStream, PRUint32
char * s = nsnull;
if (parser)
{
parser->MakeFullAddress(nsnull, userAddress, &s);
parser->MakeFullAddress(nsnull, nsnull, userAddress, &s);
NS_RELEASE(parser);
}
@ -1325,7 +1325,7 @@ PRInt32 nsSmtpProtocol::LoadURL(nsIURL * aURL)
if (parser)
{
parser->RemoveDuplicateAddresses(addresses, nsnull, PR_FALSE, &addrs1);
parser->RemoveDuplicateAddresses(nsnull, addresses, nsnull, PR_FALSE, &addrs1);
/* Extract just the mailboxes from the full RFC822 address list.
This means that people can post to mailto: URLs which contain
@ -1334,7 +1334,7 @@ PRInt32 nsSmtpProtocol::LoadURL(nsIURL * aURL)
*/
if (addrs1 && *addrs1)
{
rv = parser->ParseRFC822Addresses(addrs1, nsnull, &addrs2, m_addressesLeft);
rv = parser->ParseRFC822Addresses(nsnull, addrs1, nsnull, &addrs2, m_addressesLeft);
PR_FREEIF (addrs1);
}

View File

@ -403,7 +403,7 @@ nsresult nsMSGFolderDataSource::GetSenderName(nsAutoString& sender, nsAutoString
{
char *name;
char *senderStr = sender.ToNewCString();
if(NS_SUCCEEDED(rv = gRFC822Parser->ExtractRFC822AddressName (senderStr, &name)))
if(NS_SUCCEEDED(rv = gRFC822Parser->ExtractRFC822AddressName (nsnull, senderStr, &name)))
{
*senderUserName = name;
}

View File

@ -941,7 +941,7 @@ nsresult nsParseMailMessageState::InternRfc822 (struct message_header *header,
if (m_rfc822AddressParser)
{
ret = m_rfc822AddressParser->ExtractRFC822AddressName (header->value, &s);
ret = m_rfc822AddressParser->ExtractRFC822AddressName (nsnull, header->value, &s);
if (! s)
return NS_ERROR_OUT_OF_MEMORY;
@ -1094,7 +1094,7 @@ int nsParseMailMessageState::FinalizeHeaders()
char *names;
char *addresses;
ret = m_rfc822AddressParser->ParseRFC822Addresses (recipient->value, &names, &addresses, numAddresses);
ret = m_rfc822AddressParser->ParseRFC822Addresses (nsnull, recipient->value, &names, &addresses, numAddresses);
if (ret == NS_OK)
{
m_newMsgHdr->SetRecipientsArray(names, addresses, numAddresses);
@ -1110,7 +1110,7 @@ int nsParseMailMessageState::FinalizeHeaders()
char *names;
char *addresses;
ret = m_rfc822AddressParser->ParseRFC822Addresses (ccList->value, &names, &addresses, numAddresses);
ret = m_rfc822AddressParser->ParseRFC822Addresses (nsnull, ccList->value, &names, &addresses, numAddresses);
if (ret == NS_OK)
{
m_newMsgHdr->SetCCListArray(names, addresses, numAddresses);

View File

@ -3458,8 +3458,8 @@ PRInt32 nsNNTPProtocol::Cancel()
if (NS_SUCCEEDED(rv))
{
char *us, *them;
nsresult rv1 = parser->ExtractRFC822AddressMailboxes(from, &us);
nsresult rv2 = parser->ExtractRFC822AddressMailboxes(old_from, &them);
nsresult rv1 = parser->ExtractRFC822AddressMailboxes(nsnull, from, &us);
nsresult rv2 = parser->ExtractRFC822AddressMailboxes(nsnull, old_from, &them);
ok = (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2) && !PL_strcasecmp(us, them));
if (NS_SUCCEEDED(rv1)) PR_Free(us);