nsCString nsSmtpServer::GetServerURIInternal(const bool aIncludeUsername) { nsCString uri(NS_LITERAL_CSTRING("smtp://")); nsresult rv; if (aIncludeUsername) { nsCString username; rv = GetUsername(username); if (NS_SUCCEEDED(rv) && !username.IsEmpty()) { nsCString escapedUsername; MsgEscapeString(username, nsINetUtil::ESCAPE_XALPHAS, escapedUsername); // not all servers have a username uri.Append(escapedUsername); uri.AppendLiteral("@"); } } nsCString hostname; rv = GetHostname(hostname); if (NS_SUCCEEDED(rv) && !hostname.IsEmpty()) { nsCString escapedHostname; MsgEscapeString(hostname, nsINetUtil::ESCAPE_URL_PATH, escapedHostname); // not all servers have a hostname uri.Append(escapedHostname); } return uri; }
NS_IMETHODIMP nsSmtpServer::GetServerURI(nsACString &aResult) { nsCAutoString uri(NS_LITERAL_CSTRING("smtp://")); nsCString username; nsresult rv = GetUsername(username); if (NS_SUCCEEDED(rv) && !username.IsEmpty()) { nsCString escapedUsername; MsgEscapeString(username, nsINetUtil::ESCAPE_XALPHAS, escapedUsername); // not all servers have a username uri.Append(escapedUsername); uri.AppendLiteral("@"); } nsCString hostname; rv = GetHostname(hostname); if (NS_SUCCEEDED(rv) && !hostname.IsEmpty()) { nsCString escapedHostname; *((char **)getter_Copies(escapedHostname)) = nsEscape(hostname.get(), url_Path); // not all servers have a hostname uri.Append(escapedHostname); } aResult = uri; return NS_OK; }
/* 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; }