bool nsEudoraEditor::GetEmbeddedImageCID(PRUint32 aCIDHash, const nsAString & aOldRef, nsString &aCID) { bool foundMatch = false; PRInt32 startImageTag = 0; PRInt32 closeImageTag = 0; while ( (startImageTag = m_body.Find("<img", true, closeImageTag)) != kNotFound ) { closeImageTag = m_body.Find(">", false, startImageTag); // We should always find a close tag, bail if we don't if (closeImageTag == kNotFound) break; // Find the source attribute and make sure it's for our image tag PRInt32 startSrcValue = m_body.Find("src", true, startImageTag); if ( (startSrcValue == kNotFound) || (startSrcValue > closeImageTag) ) continue; // Move past the src startSrcValue += 3; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // We should find an = now if (m_body.CharAt(startSrcValue) != '=') continue; // Move past = ++startSrcValue; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // Get the quote char and verify that it's valid char quoteChar = static_cast <char> (m_body.CharAt(startSrcValue)); if ( (quoteChar != '"') && (quoteChar != '\'') ) continue; // Move past the quote ++startSrcValue; PRInt32 endSrcValue = m_body.FindChar(quoteChar, startSrcValue); PRInt32 srcLength = endSrcValue - startSrcValue; nsString srcValue; aCID.Assign(Substring(m_body, startSrcValue, srcLength)); if (aCIDHash != 0) { // Verify source value starts with "cid:" if (!StringBeginsWith(aCID, NS_LITERAL_STRING("cid:"), nsCaseInsensitiveStringComparator())) continue; // Remove "cid:" from the start aCID.Cut(0, 4); PRUint32 hashValue = EudoraHashString( NS_LossyConvertUTF16toASCII(aCID).get() ); foundMatch = (hashValue == aCIDHash); } else { foundMatch = aCID.Equals(aOldRef); } } return foundMatch; }
bool nsEudoraEditor::UpdateEmbeddedImageReference(PRUint32 aCIDHash, const nsAString & aOldRef, const nsAString & aUpdatedRef) { bool foundMatch = false; PRInt32 startImageTag = 0; PRInt32 closeImageTag = 0; while ( (startImageTag = m_body.Find("<img", PR_TRUE, closeImageTag)) != kNotFound ) { closeImageTag = m_body.Find(">", PR_FALSE, startImageTag); // We should always find a close tag, bail if we don't if (closeImageTag == kNotFound) break; // Find the source attribute and make sure it's for our image tag PRInt32 startSrcValue = m_body.Find("src", PR_TRUE, startImageTag); if ( (startSrcValue == kNotFound) || (startSrcValue > closeImageTag) ) continue; // Move past the src startSrcValue += 3; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // We should find an = now if (m_body.CharAt(startSrcValue) != '=') continue; // Move past = ++startSrcValue; // Move past any whitespace while ( isspace(m_body.CharAt(startSrcValue)) ) ++startSrcValue; // Get the quote char and verify that it's valid char quoteChar = static_cast <char> (m_body.CharAt(startSrcValue)); if ( (quoteChar != '"') && (quoteChar != '\'') ) continue; // Move past the quote ++startSrcValue; PRInt32 endSrcValue = m_body.Find(nsCString(quoteChar), PR_FALSE, startSrcValue); PRInt32 srcLength = endSrcValue - startSrcValue; nsString srcValue; m_body.Mid(srcValue, startSrcValue, srcLength); if (aCIDHash != 0) { // Verify source value starts with "cid:" if ( !srcValue.EqualsIgnoreCase("cid:", 4) ) continue; // Remove "cid:" from the start srcValue.Cut(0, 4); PRUint32 hashValue = EudoraHashString( NS_LossyConvertUTF16toASCII(srcValue).get() ); foundMatch = (hashValue == aCIDHash); } else { foundMatch = srcValue.Equals(aOldRef); } if (foundMatch) { m_body.Replace(startSrcValue, srcLength, aUpdatedRef); break; } } return foundMatch; }