nsresult nsBeckyFilters::CreateLeaveOrDeleteAction(const nsCString &aLine, nsIMsgFilter *aFilter, nsIMsgRuleAction **_retval) { nsresult rv; nsMsgRuleActionType actionType; if (aLine.CharAt(3) == '0') { actionType = nsMsgFilterAction::LeaveOnPop3Server; } else if (aLine.CharAt(3) == '1') { if (aLine.CharAt(5) == '1') actionType = nsMsgFilterAction::Delete; else actionType = nsMsgFilterAction::DeleteFromPop3Server; } else { return NS_ERROR_FAILURE; } nsCOMPtr<nsIMsgRuleAction> action; rv = CreateRuleAction(aFilter, actionType, getter_AddRefs(action)); NS_ENSURE_SUCCESS(rv, rv); action.forget(_retval); return NS_OK; }
nsresult nsBeckyFilters::SetRuleAction(const nsCString &aLine, nsIMsgFilter *aFilter) { if (!aFilter || aLine.Length() < 4) return NS_ERROR_FAILURE; nsresult rv = NS_OK; nsCOMPtr<nsIMsgRuleAction> action; switch (aLine.CharAt(1)) { case 'R': // Reply rv = CreateResendAction(aLine, aFilter, nsMsgFilterAction::Reply, getter_AddRefs(action)); break; case 'F': // Forward rv = CreateResendAction(aLine, aFilter, nsMsgFilterAction::Forward, getter_AddRefs(action)); break; case 'L': // Leave or delete rv = CreateLeaveOrDeleteAction(aLine, aFilter, getter_AddRefs(action)); break; case 'Y': // Copy rv = CreateDistributeAction(aLine, aFilter, nsMsgFilterAction::CopyToFolder, getter_AddRefs(action)); break; case 'M': // Move rv = CreateDistributeAction(aLine, aFilter, nsMsgFilterAction::MoveToFolder, getter_AddRefs(action)); break; case 'G': // Set flag if (aLine.CharAt(3) == 'R') // Read rv = CreateRuleAction(aFilter, nsMsgFilterAction::MarkRead, getter_AddRefs(action)); break; default: return NS_OK; } NS_ENSURE_SUCCESS(rv, rv); if (action) { rv = aFilter->AppendAction(action); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
static PRUint32 net_FindMediaDelimiter(const nsCString& flatStr, PRUint32 searchStart, char delimiter) { do { // searchStart points to the spot from which we should start looking // for the delimiter. const char delimStr[] = { delimiter, '"', '\0' }; PRUint32 curDelimPos = flatStr.FindCharInSet(delimStr, searchStart); if (curDelimPos == PRUint32(kNotFound)) return flatStr.Length(); char ch = flatStr.CharAt(curDelimPos); if (ch == delimiter) { // Found delimiter return curDelimPos; } // We hit the start of a quoted string. Look for its end. searchStart = net_FindStringEnd(flatStr, curDelimPos, ch); if (searchStart == flatStr.Length()) return searchStart; ++searchStart; // searchStart now points to the first char after the end of the // string, so just go back to the top of the loop and look for // |delimiter| again. } while (true); NS_NOTREACHED("How did we get here?"); return flatStr.Length(); }
// Return the index of the closing quote of the string, if any static PRUint32 net_FindStringEnd(const nsCString& flatStr, PRUint32 stringStart, char stringDelim) { NS_ASSERTION(stringStart < flatStr.Length() && flatStr.CharAt(stringStart) == stringDelim && (stringDelim == '"' || stringDelim == '\''), "Invalid stringStart"); const char set[] = { stringDelim, '\\', '\0' }; do { // stringStart points to either the start quote or the last // escaped char (the char following a '\\') // Write to searchStart here, so that when we get back to the // top of the loop right outside this one we search from the // right place. PRUint32 stringEnd = flatStr.FindCharInSet(set, stringStart + 1); if (stringEnd == PRUint32(kNotFound)) return flatStr.Length(); if (flatStr.CharAt(stringEnd) == '\\') { // Hit a backslash-escaped char. Need to skip over it. stringStart = stringEnd + 1; if (stringStart == flatStr.Length()) return stringStart; // Go back to looking for the next escape or the string end continue; } return stringEnd; } while (true); NS_NOTREACHED("How did we get here?"); return flatStr.Length(); }
void nsEudoraWin32::ConvertPath( nsCString& str) { nsCString temp; nsCString path; PRInt32 idx = 0; PRInt32 start = 0; nsCString search; idx = str.FindChar( '\\', idx); if ((idx == 2) && (str.CharAt( 1) == ':')) { str.Left( path, 3); idx++; idx = str.FindChar( '\\', idx); start = 3; if ((idx == -1) && (str.Length() > 3)) { str.Right( temp, str.Length() - start); path.Append( temp); } } WIN32_FIND_DATA findFileData; while (idx != -1) { str.Mid( temp, start, idx - start); search = path; search.Append( temp); HANDLE h = FindFirstFile( search.get(), &findFileData); if (h == INVALID_HANDLE_VALUE) return; path.Append( findFileData.cFileName); idx++; start = idx; idx = str.FindChar( '\\', idx); FindClose( h); if (idx != -1) path.Append( '\\'); else { str.Right( temp, str.Length() - start); path.Append( '\\'); path.Append( temp); } } str = path; }
nsresult rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI) { // This implementation is extremely simple: e.g., it can't compute // relative paths, or anything fancy like that. If the context URI // is not a prefix of the URI in question, we'll just bail. PRUint32 prefixLen = aBaseURI.Length(); if (prefixLen != 0 && StringBeginsWith(aURI, aBaseURI)) { if (prefixLen < aURI.Length() && aURI.CharAt(prefixLen) == '/') ++prefixLen; // chop the leading slash so it's not `absolute' aURI.Cut(0, prefixLen); } return NS_OK; }
void CMapiMessage::ProcessHeaderLine( nsCString& line) { PRUint32 len, start; nsCString tStr; nsCString left13; nsCString left26; nsCString left8; nsCString left5; line.Left( left13, 13); line.Left( left26, 26); line.Left( left8, 8); line.Left( left5, 5); if (left13.Equals(NS_LITERAL_CSTRING("Mime-Version:"), nsCaseInsensitiveCStringComparator())) m_bMimeVersion = TRUE; else if (left13.Equals(NS_LITERAL_CSTRING("Content-Type:"), nsCaseInsensitiveCStringComparator())) { // Note: this isn't a complete parser, the content type // we extract could have rfc822 comments in it len = 13; while ((len < line.Length()) && IsSpace( line.CharAt( len))) len++; start = len; while ((len < line.Length()) && (line.CharAt( len) != ';')) len++; line.Mid( m_mimeContentType, start, len - start); len++; // look for "boundary=" BOOL haveB; BOOL haveC; while (len < line.Length()) { haveB = FALSE; haveC = FALSE; while ((len < line.Length()) && IsSpace( line.CharAt( len))) len++; start = len; while ((len < line.Length()) && (line.CharAt( len) != '=')) len++; if (len - start) { line.Mid( tStr, start, len - start); if (tStr.Equals(NS_LITERAL_CSTRING("boundary"), nsCaseInsensitiveCStringComparator())) haveB = TRUE; else if (tStr.Equals(NS_LITERAL_CSTRING("charset"), nsCaseInsensitiveCStringComparator())) haveC = TRUE; } len++; while ((len < line.Length()) && IsSpace( line.CharAt( len))) len++; if ((len < line.Length()) && (line.CharAt( len) == '"')) { len++; BOOL slash = FALSE; tStr.Truncate(); while (len < line.Length()) { if (slash) { slash = FALSE; tStr.Append(line.CharAt( len)); } else if (line.CharAt( len) == '"') break; else if (line.CharAt( len) != '\\') tStr.Append(line.CharAt( len)); else slash = TRUE; len++; } len++; if (haveB) { m_mimeBoundary = tStr; haveB = FALSE; } if (haveC) { m_mimeCharset = tStr; haveC = FALSE; } } tStr.Truncate(); while ((len < line.Length()) && (line.CharAt( len) != ';')) { tStr.Append(line.CharAt( len)); len++; } len++; if (haveB) { tStr.Trim( kWhitespace); m_mimeBoundary = tStr; } if (haveC) { tStr.Trim( kWhitespace); m_mimeCharset = tStr; } } } else if (left26.Equals(NS_LITERAL_CSTRING("Content-Transfer-Encoding:"), nsCaseInsensitiveCStringComparator())) { m_bMimeEncoding = TRUE; } else if (left8.Equals(NS_LITERAL_CSTRING("Subject:"), nsCaseInsensitiveCStringComparator())) m_bHasSubject = TRUE; else if (left5.Equals(NS_LITERAL_CSTRING("From:"), nsCaseInsensitiveCStringComparator())) m_bHasFrom = TRUE; else if (left5.Equals(NS_LITERAL_CSTRING("Date:"), nsCaseInsensitiveCStringComparator())) m_bHasDate = TRUE; }