зеркало из https://github.com/mozilla/pjs.git
Bug #379070 --> re-write MsgFindKeyword so it doesn't take string iterators.
sr=bienvenu
This commit is contained in:
Родитель
0dcbc6fdb8
Коммит
29b9f97fd2
|
@ -5047,8 +5047,8 @@ NS_IMETHODIMP nsMsgDBFolder::AddKeywordsToMessages(nsISupportsArray *aMessages,
|
||||||
keywordArray.ParseString(nsCString(aKeywords).get(), " ");
|
keywordArray.ParseString(nsCString(aKeywords).get(), " ");
|
||||||
for (PRInt32 j = 0; j < keywordArray.Count(); j++)
|
for (PRInt32 j = 0; j < keywordArray.Count(); j++)
|
||||||
{
|
{
|
||||||
nsACString::const_iterator start, end;
|
PRInt32 start, length;
|
||||||
if (!MsgFindKeyword(*(keywordArray[j]), keywords, start, end))
|
if (!MsgFindKeyword(*(keywordArray[j]), keywords, &start, &length))
|
||||||
{
|
{
|
||||||
if (!keywords.IsEmpty())
|
if (!keywords.IsEmpty())
|
||||||
keywords.Append(' ');
|
keywords.Append(' ');
|
||||||
|
@ -5102,13 +5102,10 @@ NS_IMETHODIMP nsMsgDBFolder::RemoveKeywordsFromMessages(nsISupportsArray *aMessa
|
||||||
if (labelValue == (nsMsgLabelValue) (keywordArray[j]->CharAt(6) - '0'))
|
if (labelValue == (nsMsgLabelValue) (keywordArray[j]->CharAt(6) - '0'))
|
||||||
message->SetLabel((nsMsgLabelValue) 0);
|
message->SetLabel((nsMsgLabelValue) 0);
|
||||||
}
|
}
|
||||||
|
PRInt32 startOffset, length;
|
||||||
nsACString::const_iterator start, end;
|
if (MsgFindKeyword(*(keywordArray[j]), keywords, &startOffset,&length))
|
||||||
nsACString::const_iterator saveStart;
|
|
||||||
keywords.BeginReading(saveStart);
|
|
||||||
if (MsgFindKeyword(*(keywordArray[j]), keywords, start, end))
|
|
||||||
{
|
{
|
||||||
keywords.Cut(Distance(saveStart, start), Distance(start, end));
|
keywords.Cut(startOffset, length);
|
||||||
NS_ASSERTION(keywords.IsEmpty() || keywords.CharAt(0) != ' ', "space only keyword");
|
NS_ASSERTION(keywords.IsEmpty() || keywords.CharAt(0) != ' ', "space only keyword");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1292,20 +1292,26 @@ nsresult MsgReopenFileStream(nsILocalFile *file, nsIInputStream *fileStream)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, nsACString::const_iterator &start, nsACString::const_iterator &end)
|
PRBool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, PRInt32 *aStartOfKeyword, PRInt32 *aLength)
|
||||||
{
|
{
|
||||||
keywords.BeginReading(start);
|
const char * start = keywords.BeginReading();
|
||||||
keywords.EndReading(end);
|
const char * end = keywords.EndReading();
|
||||||
|
|
||||||
if (*start == ' ')
|
if (*start == ' ')
|
||||||
start++;
|
start++;
|
||||||
nsACString::const_iterator saveStart(start), saveEnd(end);
|
const char * saveStart = start;
|
||||||
|
const char * saveEnd = end;
|
||||||
|
PRInt32 offset = 0;
|
||||||
while (PR_TRUE)
|
while (PR_TRUE)
|
||||||
{
|
{
|
||||||
if (FindInReadable(keyword, start, end))
|
offset = keywords.Find(keyword, offset);
|
||||||
|
if (offset >= 0)
|
||||||
{
|
{
|
||||||
|
start += offset;
|
||||||
|
end = start + keyword.Length();
|
||||||
PRBool beginMatches = start == saveStart;
|
PRBool beginMatches = start == saveStart;
|
||||||
PRBool endMatches = end == saveEnd;
|
PRBool endMatches = end == saveEnd;
|
||||||
nsACString::const_iterator beforeStart(start);
|
const char * beforeStart = start;
|
||||||
beforeStart--;
|
beforeStart--;
|
||||||
// start and end point to the beginning and end of the match
|
// start and end point to the beginning and end of the match
|
||||||
if (beginMatches && (end == saveEnd || *end == ' ')
|
if (beginMatches && (end == saveEnd || *end == ' ')
|
||||||
|
@ -1316,14 +1322,19 @@ PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords, nsACStrin
|
||||||
end++;
|
end++;
|
||||||
if (*beforeStart == ' ' && endMatches)
|
if (*beforeStart == ' ' && endMatches)
|
||||||
start--;
|
start--;
|
||||||
|
*aStartOfKeyword = start - saveStart;
|
||||||
|
*aLength = end - start;
|
||||||
return PR_TRUE;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
start = end; // advance past bogus match.
|
start = end; // advance past bogus match.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*aStartOfKeyword = -1;
|
||||||
|
*aLength = 0;
|
||||||
return PR_FALSE;
|
return PR_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,9 +167,7 @@ NS_MSG_BASE nsresult MsgReopenFileStream(nsILocalFile *file, nsIInputStream *fil
|
||||||
|
|
||||||
// fills in the position of the passed in keyword in the passed in keyword list
|
// fills in the position of the passed in keyword in the passed in keyword list
|
||||||
// and returns false if the keyword isn't present
|
// and returns false if the keyword isn't present
|
||||||
NS_MSG_BASE PRBool MsgFindKeyword(const nsACString &keyword, nsACString &keywords,
|
NS_MSG_BASE PRBool MsgFindKeyword(const nsCString &keyword, nsCString &keywords, PRInt32 *aStartOfKeyword, PRInt32 *aLength);
|
||||||
nsACString::const_iterator &start,
|
|
||||||
nsACString::const_iterator &end);
|
|
||||||
|
|
||||||
NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
|
NS_MSG_BASE PRBool MsgHostDomainIsTrusted(nsCString &host, nsCString &trustedMailDomains);
|
||||||
|
|
||||||
|
|
|
@ -224,25 +224,6 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToAdd(char * *aKeywords)
|
||||||
NS_IMETHODIMP nsMsgOfflineImapOperation::AddKeywordToAdd(const char * aKeyword)
|
NS_IMETHODIMP nsMsgOfflineImapOperation::AddKeywordToAdd(const char * aKeyword)
|
||||||
{
|
{
|
||||||
return AddKeyword(aKeyword, m_keywordsToAdd, PROP_KEYWORD_ADD, m_keywordsToRemove, PROP_KEYWORD_REMOVE);
|
return AddKeyword(aKeyword, m_keywordsToAdd, PROP_KEYWORD_ADD, m_keywordsToRemove, PROP_KEYWORD_REMOVE);
|
||||||
nsACString::const_iterator start, end;
|
|
||||||
if (!MsgFindKeyword(nsDependentCString(aKeyword), m_keywordsToAdd, start, end))
|
|
||||||
{
|
|
||||||
if (!m_keywordsToAdd.IsEmpty())
|
|
||||||
m_keywordsToAdd.Append(' ');
|
|
||||||
m_keywordsToAdd.Append(aKeyword);
|
|
||||||
}
|
|
||||||
// if the keyword we're adding was in the list of keywords to remove,
|
|
||||||
// cut it from that list.
|
|
||||||
nsACString::const_iterator removeStart, removeEnd;
|
|
||||||
if (MsgFindKeyword(nsDependentCString(aKeyword), m_keywordsToRemove, removeStart, removeEnd))
|
|
||||||
{
|
|
||||||
nsACString::const_iterator saveStart;
|
|
||||||
m_keywordsToRemove.BeginReading(saveStart);
|
|
||||||
m_keywordsToRemove.Cut(Distance(saveStart, removeStart), Distance(removeStart, removeEnd));
|
|
||||||
m_mdb->SetProperty(m_mdbRow, PROP_KEYWORD_REMOVE, m_keywordsToRemove.get());
|
|
||||||
}
|
|
||||||
SetOperation(kAddKeywords);
|
|
||||||
return m_mdb->SetProperty(m_mdbRow, PROP_KEYWORD_ADD, m_keywordsToAdd.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToRemove(char * *aKeywords)
|
NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToRemove(char * *aKeywords)
|
||||||
|
@ -256,8 +237,8 @@ NS_IMETHODIMP nsMsgOfflineImapOperation::GetKeywordsToRemove(char * *aKeywords)
|
||||||
nsresult nsMsgOfflineImapOperation::AddKeyword(const char *aKeyword, nsCString &addList, const char *addProp,
|
nsresult nsMsgOfflineImapOperation::AddKeyword(const char *aKeyword, nsCString &addList, const char *addProp,
|
||||||
nsCString &removeList, const char *removeProp)
|
nsCString &removeList, const char *removeProp)
|
||||||
{
|
{
|
||||||
nsACString::const_iterator start, end;
|
PRInt32 startOffset, keywordLength;
|
||||||
if (!MsgFindKeyword(nsDependentCString(aKeyword), addList, start, end))
|
if (!MsgFindKeyword(nsDependentCString(aKeyword), addList, &startOffset, &keywordLength))
|
||||||
{
|
{
|
||||||
if (!addList.IsEmpty())
|
if (!addList.IsEmpty())
|
||||||
addList.Append(' ');
|
addList.Append(' ');
|
||||||
|
@ -265,12 +246,9 @@ nsresult nsMsgOfflineImapOperation::AddKeyword(const char *aKeyword, nsCString &
|
||||||
}
|
}
|
||||||
// if the keyword we're removing was in the list of keywords to add,
|
// if the keyword we're removing was in the list of keywords to add,
|
||||||
// cut it from that list.
|
// cut it from that list.
|
||||||
nsACString::const_iterator addStart, addEnd;
|
if (MsgFindKeyword(nsDependentCString(aKeyword), removeList, &startOffset, &keywordLength))
|
||||||
if (MsgFindKeyword(nsDependentCString(aKeyword), removeList, addStart, addEnd))
|
|
||||||
{
|
{
|
||||||
nsACString::const_iterator saveStart;
|
removeList.Cut(startOffset, keywordLength);
|
||||||
removeList.BeginReading(saveStart);
|
|
||||||
removeList.Cut(Distance(saveStart, addStart), Distance(addStart, addEnd));
|
|
||||||
m_mdb->SetProperty(m_mdbRow, removeProp, removeList.get());
|
m_mdb->SetProperty(m_mdbRow, removeProp, removeList.get());
|
||||||
}
|
}
|
||||||
SetOperation(kRemoveKeywords);
|
SetOperation(kRemoveKeywords);
|
||||||
|
|
|
@ -3782,20 +3782,16 @@ nsresult nsMsgLocalMailFolder::ChangeKeywordForMessages(nsISupportsArray *aMessa
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PRInt32 keywordHdrLength = keywordHeaders.Length();
|
PRInt32 keywordHdrLength = keywordHeaders.Length();
|
||||||
nsACString::const_iterator start, end;
|
PRInt32 startOffset, keywordLength;
|
||||||
nsACString::const_iterator keywordHdrStart;
|
|
||||||
keywordHeaders.BeginReading(keywordHdrStart);
|
|
||||||
// check if we have the keyword
|
// check if we have the keyword
|
||||||
if (MsgFindKeyword(*(keywordArray[j]), keywordHeaders, start, end))
|
if (MsgFindKeyword(*(keywordArray[j]), keywordHeaders, &startOffset, &keywordLength))
|
||||||
{
|
{
|
||||||
foundKeyword = PR_TRUE;
|
foundKeyword = PR_TRUE;
|
||||||
if (!add) // if we're removing, remove it, and break;
|
if (!add) // if we're removing, remove it, and break;
|
||||||
{
|
{
|
||||||
PRInt32 keywordStartOffset = Distance(keywordHdrStart, start);
|
keywordHeaders.Cut(startOffset, keywordLength);
|
||||||
keywordHeaders.Cut(keywordStartOffset, Distance(start, end));
|
for (PRInt32 i = keywordLength; i > 0; i--)
|
||||||
for (PRInt32 i = Distance(start, end); i > 0; i--)
|
|
||||||
keywordHeaders.Append(' ');
|
keywordHeaders.Append(' ');
|
||||||
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, lineStartPos);
|
seekableStream->Seek(nsISeekableStream::NS_SEEK_SET, lineStartPos);
|
||||||
fileStream->Write(keywordHeaders.get(), keywordHeaders.Length(), &bytesWritten);
|
fileStream->Write(keywordHeaders.get(), keywordHeaders.Length(), &bytesWritten);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче