void nsEudoraAddress::ExtractNoteField( nsCString& note, nsCString& value, const char *pFieldName)
{
  value.Truncate();
  nsCString field("<");
  field.Append( pFieldName);
  field.Append( ':');

/*
    this is a bit of a cheat, but there's no reason it won't work
    fine for us, even better than Eudora in some cases!
*/

  PRInt32 idx = note.Find( field);
  if (idx != -1) {
    idx += field.Length();
    PRInt32 endIdx = note.FindChar( '>', idx);
    if (endIdx == -1)
      endIdx = note.Length() - 1;
    note.Mid( value, idx, endIdx - idx);
    idx -= field.Length();
    nsCString tempL;
    if (idx)
      note.Left( tempL, idx);
    nsCString tempR;
    note.Right( tempR, note.Length() - endIdx - 1);
    note = tempL;
    note.Append( tempR);
  }
}
// The driver ID is a string like PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD, possibly
// followed by &REV_XXXX.  We uppercase the string, and strip the &REV_ part
// from it, if found.
static void normalizeDriverId(nsCString& driverid) {
  ToUpperCase(driverid);
  PRInt32 rev = driverid.Find(NS_LITERAL_CSTRING("&REV_"));
  if (rev != -1) {
    driverid.Cut(rev, driverid.Length());
  }
}
/* parses ImapMessageURI */
nsresult nsParseImapMessageURI(const char* uri, nsCString& folderURI, PRUint32 *key, char **part)
{
    if(!key)
        return NS_ERROR_NULL_POINTER;

    nsCAutoString uriStr(uri);
    PRInt32 folderEnd = -1;
    // imap-message uri's can have imap:// url strings tacked on the end,
    // e.g., when opening/saving attachments. We don't want to look for '#'
    // in that part of the uri, if the attachment name contains '#',
    // so check for that here.
    if (StringBeginsWith(uriStr, NS_LITERAL_CSTRING("imap-message")))
        folderEnd = uriStr.Find("imap://");

    PRInt32 keySeparator = MsgRFindChar(uriStr, '#', folderEnd);
    if(keySeparator != -1)
    {
        PRInt32 keyEndSeparator = MsgFindCharInSet(uriStr, "/?&", keySeparator);
        nsAutoString folderPath;
        folderURI = StringHead(uriStr, keySeparator);
        folderURI.Cut(4, 8); // cut out the _message part of imap-message:
        // folder uri's don't have fully escaped usernames.
        PRInt32 atPos = folderURI.FindChar('@');
        if (atPos != -1)
        {
            nsCString unescapedName, escapedName;
            PRInt32 userNamePos = folderURI.Find("//") + 2;
            PRUint32 origUserNameLen = atPos - userNamePos;
            if (NS_SUCCEEDED(MsgUnescapeString(Substring(folderURI, userNamePos,
                                               origUserNameLen),
                                               0, unescapedName)))
            {
                // Re-escape the username, matching the way we do it in uris, not the
                // way necko escapes urls. See nsMsgIncomingServer::GetServerURI.
                MsgEscapeString(unescapedName, nsINetUtil::ESCAPE_XALPHAS, escapedName);
                folderURI.Replace(userNamePos, origUserNameLen, escapedName);
            }
        }
        nsCAutoString keyStr;
        if (keyEndSeparator != -1)
            keyStr = Substring(uriStr, keySeparator + 1, keyEndSeparator - (keySeparator + 1));
        else
            keyStr = Substring(uriStr, keySeparator + 1);

        *key = strtoul(keyStr.get(), nsnull, 10);

        if (part && keyEndSeparator != -1)
        {
            PRInt32 partPos = MsgFind(uriStr, "part=", PR_FALSE, keyEndSeparator);
            if (partPos != -1)
            {
                *part = ToNewCString(Substring(uriStr, keyEndSeparator));
            }
        }
    }
    return NS_OK;
}
Exemple #4
0
void ImportAddressImpl::SanitizeSampleData(nsCString& val)
{
  // remove any line-feeds...
  PRInt32 offset = val.Find(NS_LITERAL_CSTRING("\x0D\x0A"));
  while (offset != -1) {
    val.Replace(offset, 2, ", ");
    offset = val.Find(NS_LITERAL_CSTRING("\x0D\x0A"), offset + 2);
  }
  offset = val.FindChar(13);
  while (offset != -1) {
    val.Replace(offset, 1, ',');
    offset = val.FindChar(13, offset + 2);
  }
  offset = val.FindChar(10);
  while (offset != -1) {
    val.Replace(offset, 1, ',');
    offset = val.FindChar(10, offset + 2);
  }
}
void ReplaceEolChars( nsCString& s)
{
  int        idx;
  nsCString    t;
  nsCString    rt;

  while ((idx = s.Find( "\x0D")) != -1) {
    s.Left( t, idx);
    t += "\\n";
    s.Right( rt, s.Length() - idx - 1);
    t += rt;
    s = t;
  }
  while ((idx = s.Find( "\x0A")) != -1) {
    s.Left( t, idx);
    t += "\\r";
    s.Right( rt, s.Length() - idx - 1);
    t += rt;
    s = t;
  }
}
static
void CleanUpIcalString(nsCString & data) {
    //remove all '\r\n '
    PRInt32 pos = -1;
            
    while ((pos = data.Find("\r\n ")) >= 0) {
        data.Cut(pos, 3);
    }

    char src[512] = {0};
    char dst[512] = {0};
    
    //Update TZID,
    //the exchange will use tz name some times update to TZID
    for(size_t i=0;i < TIMEZONES_COUNT; i+=2) {
        sprintf(src, "TZID:%s", TIMEZONES[i]);
        sprintf(dst, "TZID:%s", TIMEZONES[i + 1]);

        while((pos = data.Find(src)) >= 0) {
            data.Replace(pos,
                         strlen(src),
                         dst,
                         strlen(dst));
        }

        sprintf(src, "TZID=\"%s\"", TIMEZONES[i]);
        sprintf(dst, "TZID=\"%s\"", TIMEZONES[i + 1]);

        while((pos = data.Find(src)) >= 0) {
            data.Replace(pos,
                         strlen(src),
                         dst,
                         strlen(dst));
        }
    }
}
void nsEudoraAddress::ExtractNoteField(nsCString& note, nsCString& value, const char *pFieldName)
{
  value.Truncate();
  nsCString field("<");
  field.Append(pFieldName);
  field.Append(':');

/*
    this is a bit of a cheat, but there's no reason it won't work
    fine for us, even better than Eudora in some cases!
*/

  int32_t idx = note.Find(field);
  if (idx != -1) {
    idx += field.Length();
    int32_t endIdx = note.FindChar('>', idx);
    if (endIdx == -1)
      endIdx = note.Length() - 1;
    value = Substring(note, idx, endIdx - idx);
    idx -= field.Length();
    note.Cut(idx, endIdx + 1);
  }
}
Exemple #8
0
bool nsTextAddress::GetField( const char *pLine, PRInt32 maxLen, PRInt32 index, nsCString& field, char delim)
{
    bool result = false;
    const char *pChar = pLine;
    PRInt32        len = 0;
    char        tab = 9;

    field.Truncate();

    if (delim == tab)
        tab = 0;

    while (index && (len < maxLen)) {
        while (((*pChar == ' ') || (*pChar == tab)) && (len < maxLen)) {
            pChar++;
            len++;
        }
        if (len >= maxLen)
            break;
        if (*pChar == '"') {
            len = -1;
            do {
                len++;
                pChar++;
                if (((len + 1) < maxLen) && (*pChar == '"') && (*(pChar + 1) == '"')) {
                    len += 2;
                    pChar += 2;
                }
            } while ((len < maxLen) && (*pChar != '"'));
            if (len < maxLen) {
                pChar++;
                len++;
            }
        }
        if (len >= maxLen)
            break;

        while ((len < maxLen) && (*pChar != delim)) {
            len++;
            pChar++;
        }

        if (len >= maxLen)
            break;

        index--;
        pChar++;
        len++;
    }

    if (len >= maxLen) {
        return( result);
    }

    result = true;

    while ((len < maxLen) && ((*pChar == ' ') || (*pChar == tab))) {
        len++;
        pChar++;
    }

    const char *pStart = pChar;
    PRInt32        fLen = 0;
    bool          quoted = false;
    if (*pChar == '"') {
        pStart++;
        fLen = -1;
        do {
            pChar++;
            len++;
            fLen++;
            if (((len + 1) < maxLen) && (*pChar == '"') && (*(pChar + 1) == '"')) {
                quoted = true;
                len += 2;
                pChar += 2;
                fLen += 2;
            }
        } while ((len < maxLen) && (*pChar != '"'));
    }
    else {
        while ((len < maxLen) && (*pChar != delim)) {
            pChar++;
            len++;
            fLen++;
        }
    }

    if (!fLen) {
        return( result);
    }

    field.Append( pStart, fLen);
    field.Trim( kWhitespace);

    if (quoted) {
      PRInt32 offset = field.Find(NS_LITERAL_CSTRING("\"\""));
      while (offset != -1) {
        field.Cut(offset, 1);
        offset = field.Find(NS_LITERAL_CSTRING("\"\""), offset + 1);
      }
    }

    return( result);
}