Ejemplo n.º 1
0
nsresult nsMsgSearchAdapter::EncodeImapValue(char *encoding, const char *value, bool useQuotes, bool reallyDredd)
{
  // By NNTP RFC, SEARCH HEADER SUBJECT "" is legal and means 'find messages without a subject header'
  if (!reallyDredd)
  {
    // By IMAP RFC, SEARCH HEADER SUBJECT "" is illegal and will generate an error from the server
    if (!value || !value[0])
      return NS_ERROR_NULL_POINTER;
  }

  if (!NS_IsAscii(value))
  {
    nsCAutoString lengthStr;
    PL_strcat(encoding, "{");
    lengthStr.AppendInt((PRInt32) strlen(value));
    PL_strcat(encoding, lengthStr.get());
    PL_strcat(encoding, "}" CRLF);
    PL_strcat(encoding, value);
    return NS_OK;
  }
  if (useQuotes)
    PL_strcat(encoding, "\"");
  PL_strcat (encoding, value);
  if (useQuotes)
    PL_strcat(encoding, "\"");

  return NS_OK;
}
static bool ns_strnimatch(const PRUnichar *aStr, const char* aSubstring,
                            uint32_t aLen)
{
  for (; aLen; ++aStr, ++aSubstring, --aLen) {
    if (!NS_IsAscii(*aStr))
      return false;

    if (NS_ToLower((char) *aStr) != NS_ToLower(*aSubstring))
      return false;
  }

  return true;
}
Ejemplo n.º 3
0
static PRBool ns_strnimatch(const PRUnichar *aStr, const char* aSubstring,
                            PRUint32 aLen)
{
  for (; aLen; ++aStr, ++aSubstring, --aLen) {
    if (!NS_IsAscii(*aStr))
      return PR_FALSE;

    if (NS_ToLower((char) *aStr) != NS_ToLower(*aSubstring))
      return PR_FALSE;
  }

  return PR_TRUE;
}
Ejemplo n.º 4
0
static bool ns_strnmatch(const PRUnichar *aStr, const char* aSubstring,
                           PRUint32 aLen)
{
  for (; aLen; ++aStr, ++aSubstring, --aLen) {
    if (!NS_IsAscii(*aStr))
      return false;

    if ((char) *aStr != *aSubstring)
      return false;
  }

  return true;
}
/* void characters (in AString value); */
NS_IMETHODIMP sbiTunesXMLParser::Characters(const nsAString & value) {
  LOG(("Characters: %s\n", NS_LossyConvertUTF16toASCII(value).get()));
  // Calculate the bytes in the stream. This isn't perfect, but should
  // be good enough for progress calculations
  PRUnichar const * begin;
  PRUnichar const * end;
  value.BeginReading(&begin, &end);
  while (begin != end) {
    mBytesRead += NS_IsAscii(*begin++) ? 1 : 2;
  }
  
  mCharacters.Append(value);
  return NS_OK;
}
bool
nsAString::LowerCaseEqualsLiteral(const char *aASCIIString) const
{
  const PRUnichar *begin, *end;
  BeginReading(&begin, &end);

  for (; begin < end; ++begin, ++aASCIIString) {
    if (!*aASCIIString || !NS_IsAscii(*begin) ||
        NS_ToLower((char) *begin) != *aASCIIString) {
      return false;
    }
  }

  return *aASCIIString == '\0';
}
Ejemplo n.º 7
0
PRBool
nsAString::EqualsLiteral(const char *aASCIIString) const
{
  const PRUnichar *begin, *end;
  BeginReading(&begin, &end);

  for (; begin < end; ++begin, ++aASCIIString) {
    if (!*aASCIIString || !NS_IsAscii(*begin) ||
        (char) *begin != *aASCIIString) {
      return PR_FALSE;
    }
  }

  return *aASCIIString == nsnull;
}
Ejemplo n.º 8
0
static bool
ns_strnmatch(const char16_t* aStr, const char* aSubstring, uint32_t aLen)
{
  for (; aLen; ++aStr, ++aSubstring, --aLen) {
    if (!NS_IsAscii(*aStr)) {
      return false;
    }

    if ((char)*aStr != *aSubstring) {
      return false;
    }
  }

  return true;
}
Ejemplo n.º 9
0
bool
nsAString::EqualsLiteral(const char *aASCIIString) const
{
  const char16_t *begin, *end;
  BeginReading(&begin, &end);

  for (; begin < end; ++begin, ++aASCIIString) {
    if (!*aASCIIString || !NS_IsAscii(*begin) ||
        (char) *begin != *aASCIIString) {
      return false;
    }
  }

  return *aASCIIString == '\0';
}
Ejemplo n.º 10
0
bool nsAbManager::IsSafeLDIFString(const PRUnichar *aStr)
{
  // follow RFC 2849 to determine if something is safe "as is" for LDIF
  if (aStr[0] == PRUnichar(' ') ||
      aStr[0] == PRUnichar(':') ||
      aStr[0] == PRUnichar('<'))
    return PR_FALSE;

  PRUint32 i;
  PRUint32 len = NS_strlen(aStr);
  for (i=0; i<len; i++) {
    // If string contains CR or LF, it is not safe for LDIF
    // and MUST be base64 encoded
    if ((aStr[i] == PRUnichar('\n')) ||
        (aStr[i] == PRUnichar('\r')) ||
        (!NS_IsAscii(aStr[i])))
      return PR_FALSE;
  }
  return PR_TRUE;
}
Ejemplo n.º 11
0
nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset, 
                                const char16_t* inString, char** outString, 
                                char **fallbackCharset, bool *isAsciiOnly)
{
  NS_ENSURE_ARG_POINTER(contentType);
  NS_ENSURE_ARG_POINTER(charset);
  NS_ENSURE_ARG_POINTER(inString);
  NS_ENSURE_ARG_POINTER(outString);

  *outString = nullptr;

  if (NS_IsAscii(inString)) {
    if (isAsciiOnly)
      *isAsciiOnly = true;
    *outString = ToNewCString(NS_LossyConvertUTF16toASCII(inString));
    return (nullptr != *outString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
  }
  if (isAsciiOnly)
    *isAsciiOnly = false;

  bool bTEXT_HTML = false;
  nsresult res;

  if (!PL_strcasecmp(contentType, TEXT_HTML)) {
    bTEXT_HTML = true;
  }
  else if (PL_strcasecmp(contentType, TEXT_PLAIN)) {
    return NS_ERROR_ILLEGAL_VALUE;  // not supported type
  }

  nsCOMPtr <nsICharsetConverterManager> ccm =
    do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
  NS_ENSURE_SUCCESS(res, res);

  nsAutoCString charsetName;
  res = ccm->GetCharsetAlias(charset, charsetName);
  NS_ENSURE_SUCCESS(res, res);

  nsCOMPtr <nsISaveAsCharset> conv = do_CreateInstance(NS_SAVEASCHARSET_CONTRACTID, &res);
  NS_ENSURE_SUCCESS(res, res);

  // First try to transliterate, if that fails use '?' for "bad" chars.
  res = conv->Init(charsetName.get(),
                   nsISaveAsCharset::attr_FallbackQuestionMark +
                     nsISaveAsCharset::attr_EntityNone,
                   nsIEntityConverter::transliterate);
  NS_ENSURE_SUCCESS(res, res);

  const char16_t *input = inString;

  // Convert to charset
  res = conv->Convert(input, outString);

  // If the converer cannot encode to the charset,
  // then fallback to pref sepcified charsets.
  if (NS_ERROR_UENC_NOMAPPING == res && !bTEXT_HTML && fallbackCharset) {
    nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &res));
    NS_ENSURE_SUCCESS(res, res);

    nsAutoCString prefString("intl.fallbackCharsetList.");
    prefString.Append(charset);
    nsCString fallbackList;
    res = prefBranch->GetCharPref(prefString.get(), getter_Copies(fallbackList));
    // do the fallback only if there is a pref for the charset
    if (NS_FAILED(res) || fallbackList.IsEmpty())
      return NS_ERROR_UENC_NOMAPPING;

    res = conv->Init(fallbackList.get(), 
                     nsISaveAsCharset::attr_FallbackQuestionMark + 
                     nsISaveAsCharset::attr_EntityAfterCharsetConv +
                     nsISaveAsCharset::attr_CharsetFallback, 
                     nsIEntityConverter::transliterate);
    NS_ENSURE_SUCCESS(res, res);

    // free whatever we have now
    PR_FREEIF(*outString);  

    res = conv->Convert(input, outString);
    NS_ENSURE_SUCCESS(res, res);

    // get the actual charset used for the conversion
    if (NS_FAILED(conv->GetCharset(fallbackCharset)))
      *fallbackCharset = nullptr;
  }
  // Exclude stateful charset which is 7 bit but not ASCII only.
  else if (isAsciiOnly && *outString &&
           !nsMsgI18Nstateful_charset(charsetName.get()))
    *isAsciiOnly = NS_IsAscii(*outString);

  return res;
}