added few more utils to get hostname, username, & protocol type from uri
This commit is contained in:
Родитель
4ff1f8b51b
Коммит
8fba233f81
|
@ -144,7 +144,7 @@ nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult)
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsImapURI2Name(const char* rootURI, char* uriStr, nsString& name)
|
||||
nsImapURI2Name(const char* rootURI, const char* uriStr, nsString& name)
|
||||
{
|
||||
nsAutoString uri = uriStr;
|
||||
if (uri.Find(rootURI) != 0) // if doesn't start with rootURI
|
||||
|
@ -174,6 +174,54 @@ nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsImapURI2UserName(const char* rootURI, const char* uriStr,
|
||||
nsString& username)
|
||||
{
|
||||
nsAutoString uri = uriStr;
|
||||
if (uri.Find(rootURI) != 0) return NS_ERROR_FAILURE;
|
||||
PRInt32 userStart = PL_strlen(rootURI);
|
||||
while (uri[userStart] == '/') userStart++;
|
||||
uri.Cut(0, userStart);
|
||||
PRInt32 userEnd = uri.Find('@');
|
||||
if (userEnd < 1)
|
||||
return NS_ERROR_FAILURE;
|
||||
uri.SetLength(userEnd);
|
||||
username = uri;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsImapURI2HostName(const char* rootURI, const char* uriStr,
|
||||
nsString& hostname)
|
||||
{
|
||||
nsAutoString uri = uriStr;
|
||||
if (uri.Find(rootURI) != 0) return NS_ERROR_FAILURE;
|
||||
PRInt32 hostStart = PL_strlen(rootURI);
|
||||
while (uri[hostStart] == '/') hostStart++;
|
||||
uri.Cut(0, hostStart);
|
||||
hostStart = uri.Find('@'); // skip username
|
||||
if (hostStart > 0)
|
||||
uri.Cut(0, hostStart+1);
|
||||
PRInt32 hostEnd = uri.Find('/');
|
||||
if (hostEnd > 0)
|
||||
uri.SetLength(hostEnd);
|
||||
hostname = uri;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsURI2ProtocolType(const char* uriStr, nsString& type)
|
||||
{
|
||||
nsAutoString uri = uriStr;
|
||||
PRInt32 typeEnd = uri.Find(':');
|
||||
if (typeEnd < 1)
|
||||
return NS_ERROR_FAILURE;
|
||||
uri.SetLength(typeEnd);
|
||||
type = uri;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* parses ImapMessageURI */
|
||||
nsresult nsParseImapMessageURI(const char* uri, nsString& folderURI, PRUint32 *key)
|
||||
{
|
||||
|
|
|
@ -29,18 +29,30 @@ extern nsresult
|
|||
nsGetImapRoot(const char* hostname, nsFileSpec &result);
|
||||
|
||||
extern nsresult
|
||||
nsImapURI2Path(const char* rootURI, const char* uriStr, nsFileSpec& pathResult);
|
||||
nsImapURI2Path(const char* rootURI, const char* uriStr,
|
||||
nsFileSpec& pathResult);
|
||||
|
||||
extern nsresult
|
||||
nsPath2ImapURI(const char* rootURI, const nsFileSpec& path, char* *uri);
|
||||
|
||||
extern nsresult
|
||||
nsImapURI2Name(const char* rootURI, char* uriStr, nsString& name);
|
||||
nsImapURI2Name(const char* rootURI, const char* uriStr, nsString& name);
|
||||
|
||||
extern nsresult
|
||||
nsImapURI2FullName(const char* rootURI, const char* hostname, char* uriStr,
|
||||
nsString& name);
|
||||
|
||||
extern nsresult
|
||||
nsImapURI2HostName(const char *rootURI, const char* uriStr,
|
||||
nsString& hostname);
|
||||
|
||||
extern nsresult
|
||||
nsImapURI2UserName(const char *rootURI, const char* uriStr,
|
||||
nsString& username);
|
||||
|
||||
extern nsresult
|
||||
nsURI2ProtocolType(const char* uriStr, nsString& type);
|
||||
|
||||
extern nsresult
|
||||
nsParseImapMessageURI(const char* uri, nsString& folderURI, PRUint32 *key);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче