Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes
nsNntpService Class Reference

#include <nsNntpService.h>

Inheritance diagram for nsNntpService:
Inheritance graph
[legend]
Collaboration diagram for nsNntpService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSINNTPSERVICE
NS_DECL_NSIMSGMESSAGESERVICE
NS_DECL_NSIPROTOCOLHANDLER
NS_DECL_NSIMSGPROTOCOLINFO
NS_DECL_NSICONTENTHANDLER
NS_DECL_NSIMSGMESSAGEFETCHPARTSERVICE
NS_DECL_NSICMDLINEHANDLER
CMDLINEHANDLER_REGISTERPROC_DECLS 
nsNntpService ()
virtual ~nsNntpService ()
void generateNewsHeaderValsForPosting (in string newsgroupsList, out string newsgroupsHeaderVal, out string newshostHeaderVal)
nsIURI postMessage (in nsIFileSpec fileToPost, in string newsgroupNames, in string aAccountKey, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow)
nsIURI getNewNews (in nsINntpIncomingServer nntpServer, in string uri, in boolean getOld, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow)
nsIURI cancelMessage (in string cancelURL, in string messageURI, in nsISupports aConsumer, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow)
void getListOfGroupsOnServer (in nsINntpIncomingServer nntpServer, in nsIMsgWindow aMsgWindow)
void updateCounts (in nsINntpIncomingServer nntpServer, in nsIMsgWindow aMsgWindow)
nsIURI fetchMessage (in nsIMsgFolder newsFolder, in nsMsgKey key, in nsIMsgWindow aMsgWindow, in nsISupports aConsumer, in nsIUrlListener aUrlListener)
void downloadNewsgroupsForOffline (in nsIMsgWindow aMsgWindow, in nsIUrlListener aListener)
void decomposeNewsURI (in string uri, out nsIMsgFolder folder, out nsMsgKey key)
 can handle news-message:// and news://
void CopyMessage (in string aSrcURI, in nsIStreamListener aCopyListener, in boolean aMoveMessage, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow, out nsIURI aURL)
void CopyMessages (in nsMsgKeyArrayPtr keys, in nsIMsgFolder srcFolder, in nsIStreamListener aCopyListener, in boolean aMoveMessage, in nsIUrlListener aUrlListener, in nsIMsgWindow aMsgWindow, out nsIURI aURL)
void DisplayMessage (in string aMessageURI, in nsISupports aDisplayConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener, in string aCharsetOverride, out nsIURI aURL)
void openAttachment (in string aContentType, in string aFileName, in string aUrl, in string aMessageUri, in nsISupports aDisplayConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener)
void SaveMessageToDisk (in string aMessageURI, in nsIFileSpec aFile, in boolean aGenerateDummyEnvelope, in nsIUrlListener aUrlListener, out nsIURI aURL, in boolean canonicalLineEnding, in nsIMsgWindow aMsgWindow)
void GetUrlForUri (in string aMessageURI, out nsIURI aURL, in nsIMsgWindow aMsgWindow)
void DisplayMessageForPrinting (in string aMessageURI, in nsISupports aDisplayConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener, out nsIURI aURL)
void Search (in nsIMsgSearchSession aSearchSession, in nsIMsgWindow aMsgWindow, in nsIMsgFolder aMsgFolder, in string aSearchUri)
nsIURI streamMessage (in string aMessageURI, in nsISupports aConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener, in boolean aConvertData, in string aAdditionalHeader)
nsIMsgDBHdr messageURIToMsgHdr (in string uri)
 now the the message datasource is going away we need away to go from message uri to go nsIMsgDBHdr
nsIURI fetchMimePart (in nsIURI aURI, in string aMessageUri, in nsISupports aDisplayConsumer, in nsIMsgWindow aMsgWindow, in nsIUrlListener aUrlListener)
nsIURI newURI (in AUTF8String aSpec, in string aOriginCharset, in nsIURI aBaseURI)
 Makes a URI object that is suitable for loading by this protocol, where the URI string is given as an UTF-8 string.
nsIChannel newChannel (in nsIURI aURI)
 Constructs a new channel from the given URI for this protocol handler.
boolean allowPort (in long port, in string scheme)
 Allows a protocol to override blacklisted ports.
long getDefaultServerPort (in boolean isSecure)
void handleContent (in string aContentType, in nsIInterfaceRequestor aWindowContext, in nsIRequest aRequest)
 Tells the content handler to take over handling the content.

Public Attributes

readonly attribute nsICacheSession cacheSession
readonly attribute ACString scheme
 The scheme of this protocol (e.g., "file").
readonly attribute long defaultPort
 The default port is the port that this protocol normally uses.
readonly attribute unsigned long protocolFlags
 Returns the protocol specific flags (see flag definitions below).
const unsigned long URI_STD = 0
 standard full URI with authority component and concept of relative URIs (http, ftp, ...)
const unsigned long URI_NORELATIVE = (1<<0)
 no concept of relative URIs (about, javascript, finger, ...)
const unsigned long URI_NOAUTH = (1<<1)
 no authority component (file, ...)
const unsigned long ALLOWS_PROXY = (1<<2)
 This protocol handler can be proxied via a proxy (socks or http) (e.g., irc, smtp, http, etc.).
const unsigned long ALLOWS_PROXY_HTTP = (1<<3)
 This protocol handler can be proxied using a http proxy (e.g., http, ftp, etc.).
attribute nsIFileSpec defaultLocalPath
 the default path to store local data for this type of server.
readonly attribute nsIIDPtr serverIID
 the IID of the protocol-specific interface for this server usually used from JS to dynamically get server-specific attributes
readonly attribute boolean requiresUsername
 does this server type require a username? for instance, news does not but IMAP/POP do
readonly attribute boolean preflightPrettyNameWithEmailAddress
 if the pretty name of the server should just be the e-mail address.
readonly attribute boolean canDelete
 can this type of server be removed from the account manager? for instance, local mail is not removable
readonly attribute boolean canLoginAtStartUp
 can this type of server log in at startup?
readonly attribute boolean canDuplicate
 can you duplicate this server? for instance, local mail is unique and should not be duplicated.
readonly attribute boolean canGetMessages
 An attribute that tell us whether on not we can get messages for the given server type this is poorly named right now.
readonly attribute boolean canGetIncomingMessages
 do messages arrive for this server if they do, we can use our junk controls on it.
readonly attribute boolean defaultDoBiff
 do biff by default?
readonly attribute boolean showComposeMsgLink
 do we need to show compose message link in the AccountCentral page ?
readonly attribute boolean needToBuildSpecialFolderURIs
 do we need to build special folder URIs ? In case of IMAP, special folders like 'Sent', 'Drafts' and 'Templates' are not created unless needed.
readonly attribute boolean specialFoldersDeletionAllowed
 do we allow special folder deletion ?

Protected Member Functions

PRBool WeAreOffline ()
nsresult GetNntpServerByAccount (const char *aAccountKey, nsIMsgIncomingServer **aNntpServer)
nsresult SetUpNntpUrlForPosting (const char *aAccountKey, char **newsUrlSpec)
nsresult FindHostFromGroup (nsCString &host, nsCString &groupName)
nsresult FindServerWithNewsgroup (nsCString &host, nsCString &groupName)
nsresult CreateMessageIDURL (nsIMsgFolder *folder, nsMsgKey key, char **url)
nsresult ConstructNntpUrl (const char *urlString, nsIUrlListener *aUrlListener, nsIMsgWindow *aMsgWindow, const char *originalMessageUri, PRInt32 action, nsIURI **aUrl)
nsresult CreateNewsAccount (const char *aHostname, PRBool aIsSecure, PRInt32 aPort, nsIMsgIncomingServer **aServer)
nsresult GetProtocolForUri (nsIURI *aUri, nsIMsgWindow *aMsgWindow, nsINNTPProtocol **aProtocol)
nsresult RunNewsUrl (nsIURI *aUrl, nsIMsgWindow *aMsgWindow, nsISupports *aConsumer)
nsresult GetFolderFromUri (const char *uri, nsIMsgFolder **folder)
nsresult DecomposeNewsMessageURI (const char *aMessageURI, nsIMsgFolder **aFolder, nsMsgKey *aMsgKey)

Static Protected Member Functions

static PRBool findNewsServerWithGroup (nsISupports *aElement, void *data)

Protected Attributes

PRBool mPrintingOperation
PRBool mOpenAttachmentOperation
nsCOMPtr< nsICacheSessionmCacheSession

Detailed Description

Definition at line 66 of file nsNntpService.h.


Constructor & Destructor Documentation

Definition at line 111 of file nsNntpService.cpp.

{
  // do nothing
}

Member Function Documentation

boolean nsIProtocolHandler::allowPort ( in long  port,
in string  scheme 
) [inherited]

Allows a protocol to override blacklisted ports.

This method will be called when there is an attempt to connect to a port that is blacklisted. For example, for most protocols, port 25 (Simple Mail Transfer) is banned. When a URI containing this "known-to-do-bad-things" port number is encountered, this function will be called to ask if the protocol handler wants to override the ban.

nsIURI nsINntpService::cancelMessage ( in string  cancelURL,
in string  messageURI,
in nsISupports  aConsumer,
in nsIUrlListener  aUrlListener,
in nsIMsgWindow  aMsgWindow 
) [inherited]
nsresult nsNntpService::ConstructNntpUrl ( const char *  urlString,
nsIUrlListener aUrlListener,
nsIMsgWindow aMsgWindow,
const char *  originalMessageUri,
PRInt32  action,
nsIURI **  aUrl 
) [protected]

Definition at line 1001 of file nsNntpService.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr <nsINntpUrl> nntpUrl = do_CreateInstance(NS_NNTPURL_CONTRACTID,&rv);
  NS_ENSURE_SUCCESS(rv,rv);
  
  nsCOMPtr <nsIMsgMailNewsUrl> mailnewsurl = do_QueryInterface(nntpUrl);
  mailnewsurl->SetMsgWindow(aMsgWindow);
  nsCOMPtr <nsIMsgMessageUrl> msgUrl = do_QueryInterface(nntpUrl);
  msgUrl->SetUri(originalMessageUri);
  mailnewsurl->SetSpec(nsDependentCString(urlString));
  nntpUrl->SetNewsAction(action);
  
  if (originalMessageUri)
  {
    // we'll use this later in nsNNTPProtocol::ParseURL()
    rv = msgUrl->SetOriginalSpec(originalMessageUri);
    NS_ENSURE_SUCCESS(rv,rv);
  }

  if (aUrlListener) // register listener if there is one...
    mailnewsurl->RegisterListener(aUrlListener);

  (*aUrl) = mailnewsurl;
  NS_IF_ADDREF(*aUrl);
  return rv;
}

Here is the call graph for this function:

void nsIMsgMessageService::CopyMessage ( in string  aSrcURI,
in nsIStreamListener  aCopyListener,
in boolean  aMoveMessage,
in nsIUrlListener  aUrlListener,
in nsIMsgWindow  aMsgWindow,
out nsIURI  aURL 
) [inherited]
void nsIMsgMessageService::CopyMessages ( in nsMsgKeyArrayPtr  keys,
in nsIMsgFolder  srcFolder,
in nsIStreamListener  aCopyListener,
in boolean  aMoveMessage,
in nsIUrlListener  aUrlListener,
in nsIMsgWindow  aMsgWindow,
out nsIURI  aURL 
) [inherited]
nsresult nsNntpService::CreateMessageIDURL ( nsIMsgFolder folder,
nsMsgKey  key,
char **  url 
) [protected]

Definition at line 199 of file nsNntpService.cpp.

{
    NS_ENSURE_ARG_POINTER(folder);
    NS_ENSURE_ARG_POINTER(url);
    if (key == nsMsgKey_None) return NS_ERROR_INVALID_ARG;
    
    nsresult rv;
    nsCOMPtr <nsIMsgNewsFolder> newsFolder = do_QueryInterface(folder, &rv);
    NS_ENSURE_SUCCESS(rv,rv);

    nsXPIDLCString messageID;
    rv = newsFolder->GetMessageIdForKey(key, getter_Copies(messageID));
    NS_ENSURE_SUCCESS(rv,rv);

    // we need to escape the message ID, 
    // it might contain characters which will mess us up later, like #
    // see bug #120502
    char *escapedMessageID = nsEscape(messageID.get(), url_Path);
    if (!escapedMessageID)
      return NS_ERROR_OUT_OF_MEMORY;

    nsCOMPtr <nsIMsgFolder> rootFolder;
    rv = folder->GetRootFolder(getter_AddRefs(rootFolder));
    NS_ENSURE_SUCCESS(rv,rv);
    
    nsXPIDLCString rootFolderURI;
    rv = rootFolder->GetURI(getter_Copies(rootFolderURI));
    NS_ENSURE_SUCCESS(rv,rv);

    nsCAutoString uri;
    uri = rootFolderURI.get();
    uri += '/';
    uri += escapedMessageID;
    *url = nsCRT::strdup(uri.get());
    
    PR_FREEIF(escapedMessageID);

    if (!*url) 
      return NS_ERROR_OUT_OF_MEMORY;
    
    return NS_OK;
}

Here is the call graph for this function:

nsresult nsNntpService::CreateNewsAccount ( const char *  aHostname,
PRBool  aIsSecure,
PRInt32  aPort,
nsIMsgIncomingServer **  aServer 
) [protected]

Definition at line 1031 of file nsNntpService.cpp.

{
  NS_ENSURE_ARG_POINTER(aHostname);
  NS_ENSURE_ARG_POINTER(aServer);
  
  nsresult rv;       
  nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  
  nsCOMPtr <nsIMsgAccount> account;
  rv = accountManager->CreateAccount(getter_AddRefs(account));
  if (NS_FAILED(rv)) return rv;
  
  // for news, username is always null
  rv = accountManager->CreateIncomingServer(nsnull /* username */, aHostname, "nntp", aServer);
  if (NS_FAILED(rv)) return rv;
  
  rv = (*aServer)->SetIsSecure(aIsSecure);
  if (NS_FAILED(rv)) return rv;
  
  rv = (*aServer)->SetPort(aPort);
  if (NS_FAILED(rv)) return rv;
  
  nsCOMPtr <nsIMsgIdentity> identity;
  rv = accountManager->CreateIdentity(getter_AddRefs(identity));
  if (NS_FAILED(rv)) return rv;
  if (!identity) return NS_ERROR_FAILURE;
  
  // by default, news accounts should be composing in plain text
  rv = identity->SetComposeHtml(PR_FALSE);
  NS_ENSURE_SUCCESS(rv,rv);
  
  // the identity isn't filled in, so it is not valid.
  rv = (*aServer)->SetValid(PR_FALSE);
  if (NS_FAILED(rv)) return rv;
  
  // hook them together
  rv = account->SetIncomingServer(*aServer);
  if (NS_FAILED(rv)) return rv;
  rv = account->AddIdentity(identity);
  if (NS_FAILED(rv)) return rv;
  
  // Now save the new acct info to pref file.
  rv = accountManager->SaveAccountInfo();
  if (NS_FAILED(rv)) return rv;
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNntpService::DecomposeNewsMessageURI ( const char *  aMessageURI,
nsIMsgFolder **  aFolder,
nsMsgKey aMsgKey 
) [protected]

Definition at line 537 of file nsNntpService.cpp.

{
    NS_ENSURE_ARG_POINTER(aMessageURI);
    NS_ENSURE_ARG_POINTER(aFolder);
    NS_ENSURE_ARG_POINTER(aMsgKey);

    nsresult rv = NS_OK;
    nsCAutoString folderURI;
#if 0 // this not ready yet.
    // check if we have a url of this form:
    // "news://news.mozilla.org:119/3D612B96.1050301%40netscape.com?part=1.2&type=image/gif&filename=hp_icon_logo.gif"
    // if so, we're going to iterate through the open msg windows, finding ones with news folders loaded,
    // opening the db's for those folders, and searching for messages with the message id
    if (!PL_strncmp(aMessageURI, kNewsRootURI, kNewsRootURILen)) {
      nsCAutoString messageUri(aMessageURI + kNewsRootURILen + 1);
      PRInt32 slashPos = messageUri.FindChar('/');
      if (slashPos != kNotFound && slashPos + 1 != messageUri.Length())
      {
        nsCAutoString messageId;
        PRInt32 questionPos = messageUri.FindChar('?');
        if (questionPos == kNotFound)
          questionPos = messageUri.Length();

        PRInt32 atPos = messageUri.Find("%40");
        if (atPos != kNotFound)
        {
          PRInt32 messageIdLength = questionPos - slashPos - 1;
          messageUri.Mid(messageId, slashPos + 1, messageIdLength);
          nsUnescape(messageId.BeginWriting());
          nsCOMPtr<nsIMsgMailSession> mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
          NS_ENSURE_SUCCESS(rv, rv);
          nsCOMPtr <nsISupportsArray> msgWindows;
          rv = mailSession->GetMsgWindowsArray(getter_AddRefs(msgWindows));
          NS_ENSURE_SUCCESS(rv, rv);
          PRUint32 numMsgWindows;
          msgWindows->Count(&numMsgWindows);
          for (PRUint32 windowIndex = 0; windowIndex < numMsgWindows; windowIndex++)
          {
            nsCOMPtr <nsIMsgWindow> msgWindow = do_QueryElementAt(msgWindows, windowIndex);
            NS_ENSURE_SUCCESS(rv, rv);
            nsCOMPtr <nsIMsgFolder> openFolder;
            msgWindow->GetOpenFolder(getter_AddRefs(openFolder));
            if (openFolder)
            {
              nsCOMPtr <nsIMsgNewsFolder> newsFolder = do_QueryInterface(openFolder);
              // only interested in news folders.
              if (newsFolder)
              {
                nsCOMPtr <nsIMsgDatabase> msgDatabase;
                openFolder->GetMsgDatabase(msgWindow, getter_AddRefs(msgDatabase));
                if (msgDatabase)
                {
                  nsCOMPtr <nsIMsgDBHdr> msgHdr;
                  msgDatabase->GetMsgHdrForMessageID(messageId.get(), getter_AddRefs(msgHdr));
                  if (msgHdr)
                  {
                    msgHdr->GetMessageKey(aMsgKey);
                    NS_ADDREF(*aFolder = openFolder);
                    break;
                  }
                }
              }
            }
          }
        }
      }
    }
    else
#endif
    {
      rv = nsParseNewsMessageURI(aMessageURI, folderURI, aMsgKey);
      NS_ENSURE_SUCCESS(rv,rv);

      rv = GetFolderFromUri(folderURI.get(), aFolder);
      NS_ENSURE_SUCCESS(rv,rv);
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsINntpService::decomposeNewsURI ( in string  uri,
out nsIMsgFolder  folder,
out nsMsgKey  key 
) [inherited]

can handle news-message:// and news://

void nsIMsgMessageService::DisplayMessage ( in string  aMessageURI,
in nsISupports  aDisplayConsumer,
in nsIMsgWindow  aMsgWindow,
in nsIUrlListener  aUrlListener,
in string  aCharsetOverride,
out nsIURI  aURL 
) [inherited]

Here is the caller graph for this function:

void nsIMsgMessageService::DisplayMessageForPrinting ( in string  aMessageURI,
in nsISupports  aDisplayConsumer,
in nsIMsgWindow  aMsgWindow,
in nsIUrlListener  aUrlListener,
out nsIURI  aURL 
) [inherited]
nsIURI nsINntpService::fetchMessage ( in nsIMsgFolder  newsFolder,
in nsMsgKey  key,
in nsIMsgWindow  aMsgWindow,
in nsISupports  aConsumer,
in nsIUrlListener  aUrlListener 
) [inherited]
nsIURI nsIMsgMessageFetchPartService::fetchMimePart ( in nsIURI  aURI,
in string  aMessageUri,
in nsISupports  aDisplayConsumer,
in nsIMsgWindow  aMsgWindow,
in nsIUrlListener  aUrlListener 
) [inherited]
nsresult nsNntpService::FindHostFromGroup ( nsCString host,
nsCString groupName 
) [protected]

Definition at line 757 of file nsNntpService.cpp.

{
  nsresult rv = NS_OK;
  // host always comes in as ""
  NS_ASSERTION(host.IsEmpty(), "host is not empty");
  if (!host.IsEmpty()) return NS_ERROR_FAILURE;
 
  rv = FindServerWithNewsgroup(host, groupName);
  NS_ENSURE_SUCCESS(rv,rv);

  // host can be empty
  return NS_OK;
}

Here is the call graph for this function:

PRBool nsNntpService::findNewsServerWithGroup ( nsISupports *  aElement,
void data 
) [static, protected]

Definition at line 696 of file nsNntpService.cpp.

{
  nsresult rv;
  
  nsCOMPtr<nsINntpIncomingServer> newsserver = do_QueryInterface(aElement, &rv);
  if (NS_FAILED(rv) || ! newsserver) return PR_TRUE;
  
  findNewsServerEntry *entry = (findNewsServerEntry*) data;
  
  PRBool containsGroup = PR_FALSE;
  
  NS_ASSERTION(IsUTF8(nsDependentCString(entry->newsgroup)),
                      "newsgroup is not in UTF-8");
  rv = newsserver->ContainsNewsgroup(nsDependentCString(entry->newsgroup),
                                     &containsGroup);
  if (NS_FAILED(rv)) return PR_TRUE;
  
  if (containsGroup) 
  {    
    entry->server = newsserver;
    return PR_FALSE;            // stop on first find
  }
  else 
  {
    return PR_TRUE;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNntpService::FindServerWithNewsgroup ( nsCString host,
nsCString groupName 
) [protected]

Definition at line 725 of file nsNntpService.cpp.

{
  nsresult rv;

  nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  nsCOMPtr<nsISupportsArray> servers;
  
  rv = accountManager->GetAllServers(getter_AddRefs(servers));
  NS_ENSURE_SUCCESS(rv,rv);

  findNewsServerEntry serverInfo;
  serverInfo.server = nsnull;
  serverInfo.newsgroup = groupName.get();

  // XXX TODO
  // this only looks at the list of subscribed newsgroups.  
  // fix to use the hostinfo.dat information
  servers->EnumerateForwards(findNewsServerWithGroup, (void *)&serverInfo);
  if (serverInfo.server) 
  {
    nsCOMPtr<nsIMsgIncomingServer> server = do_QueryInterface(serverInfo.server);
    nsXPIDLCString thisHostname;
    rv = server->GetRealHostName(getter_Copies(thisHostname));
    NS_ENSURE_SUCCESS(rv,rv);
   
    host = (const char *)thisHostname;
  }
  
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsINntpService::generateNewsHeaderValsForPosting ( in string  newsgroupsList,
out string  newsgroupsHeaderVal,
out string  newshostHeaderVal 
) [inherited]
nsresult nsNntpService::GetFolderFromUri ( const char *  uri,
nsIMsgFolder **  folder 
) [protected]

Definition at line 617 of file nsNntpService.cpp.

{
  NS_ENSURE_ARG_POINTER(aUri);
  NS_ENSURE_ARG_POINTER(aFolder);

  nsCOMPtr<nsIURI> uri;
  nsresult rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aUri));
  NS_ENSURE_SUCCESS(rv,rv);

  nsCAutoString path;
  rv = uri->GetPath(path);
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr <nsIMsgIncomingServer> server;
  rv = accountManager->FindServerByURI(uri, PR_FALSE, getter_AddRefs(server));
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr <nsIMsgFolder> rootFolder;
  rv = server->GetRootFolder(getter_AddRefs(rootFolder));
  NS_ENSURE_SUCCESS(rv,rv);

  // check if path is "/"
  // if so, use the root folder
  if (path.Length() == 1)
  {
    NS_ADDREF(*aFolder = rootFolder);
    return NS_OK;
  }

  // the URI is news://host/(escaped group)
  // but the *name* of the newsgroup (we are calling ::GetChildNamed())
  // is unescaped.  see http://bugzilla.mozilla.org/show_bug.cgi?id=210089#c17
  // for more about this
  char *unescapedPath = PL_strdup(path.get() + 1); /* skip the leading slash */
  if (!unescapedPath)
    return NS_ERROR_OUT_OF_MEMORY;
  nsUnescape(unescapedPath);

  nsCOMPtr<nsISupports> subFolder;
  rv = rootFolder->GetChildNamed(NS_ConvertUTF8toUTF16(unescapedPath).get() ,
                                 getter_AddRefs(subFolder));
  PL_strfree(unescapedPath);
  NS_ENSURE_SUCCESS(rv,rv);

  return CallQueryInterface(subFolder, aFolder);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIURI nsINntpService::getNewNews ( in nsINntpIncomingServer  nntpServer,
in string  uri,
in boolean  getOld,
in nsIUrlListener  aUrlListener,
in nsIMsgWindow  aMsgWindow 
) [inherited]
nsresult nsNntpService::GetNntpServerByAccount ( const char *  aAccountKey,
nsIMsgIncomingServer **  aNntpServer 
) [protected]

Definition at line 925 of file nsNntpService.cpp.

{
  NS_ENSURE_ARG_POINTER(aNntpServer);
  nsresult rv = NS_ERROR_FAILURE;

  nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);
  if (aAccountKey)
  {
    nsCOMPtr <nsIMsgAccount> account;
    rv = accountManager->GetAccount(aAccountKey, getter_AddRefs(account));
    if (NS_SUCCEEDED(rv) && account)
      rv = account->GetIncomingServer(aNntpServer);
  }

  // if we don't have a news host, find the first news server and use it
  if (NS_FAILED(rv) || !*aNntpServer)
    rv = accountManager->FindServer("","","nntp", aNntpServer);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNntpService::GetProtocolForUri ( nsIURI aUri,
nsIMsgWindow aMsgWindow,
nsINNTPProtocol **  aProtocol 
) [protected]

Definition at line 1081 of file nsNntpService.cpp.

{
  nsCAutoString hostName;
  nsCAutoString scheme;
  nsCAutoString path;
  PRInt32 port = 0;
  nsresult rv;
  
  rv = aUri->GetAsciiHost(hostName);
  rv = aUri->GetScheme(scheme);
  rv = aUri->GetPort(&port);
  rv = aUri->GetPath(path);

  nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  // find the incoming server, it if exists.
  // migrate if necessary, before searching for it.
  // if it doesn't exist, create it.
  nsCOMPtr<nsIMsgIncomingServer> server;
  nsCOMPtr<nsINntpIncomingServer> nntpServer;

#ifdef DEBUG_sspitzer
  printf("for bug, #36661, see if there are any accounts, if not, try migrating.  should this be pushed into FindServer()?\n");
#endif
  nsCOMPtr <nsISupportsArray> accounts;
  rv = accountManager->GetAccounts(getter_AddRefs(accounts));
  if (NS_FAILED(rv)) return rv;

  PRUint32 accountCount;
  rv = accounts->Count(&accountCount);
  if (NS_FAILED(rv)) return rv;

  if (accountCount == 0)
  {
       nsCOMPtr <nsIMessengerMigrator> messengerMigrator = do_GetService(kMessengerMigratorCID, &rv);
    if (NS_FAILED(rv)) return rv;
    if (!messengerMigrator) return NS_ERROR_FAILURE;

    // migration can fail;
    messengerMigrator->UpgradePrefs(); 
  }

  // news:group becomes news://group, so we have three types of urls:
  // news://group       (autosubscribing without a host)
  // news://host/group  (autosubscribing with a host)
  // news://host        (updating the unread message counts on a server)
  //
  // first, check if hostName is really a server or a group
  // by looking for a server with hostName
  //
  // xxx todo what if we have two servers on the same host, but different ports?
  // or no port, but isSecure (snews:// vs news://) is different?
  rv = accountManager->FindServerByURI(aUri, PR_FALSE,
                                getter_AddRefs(server));

  if (!server)
  {
    // try the "real" settings ("realservername" and "realusername")
    rv = accountManager->FindServerByURI(aUri, PR_TRUE,
                                getter_AddRefs(server));
  }

  // if we didn't find the server, and path was "/", this is a news://group url
  if (!server && !strcmp("/",path.get())) 
  {
    // the uri was news://group and we want to turn that into news://host/group
    // step 1, set the path to be the hostName;
    rv = aUri->SetPath(hostName);
    NS_ENSURE_SUCCESS(rv,rv);

    // until we support default news servers, use the first nntp server we find
    rv = accountManager->FindServerByURI(aUri, PR_FALSE, getter_AddRefs(server));
    if (NS_FAILED(rv) || !server)
    {
        // step 2, set the uri's hostName and the local variable hostName
        // to be "news"
        rv = aUri->SetHost(NS_LITERAL_CSTRING("news"));
        NS_ENSURE_SUCCESS(rv,rv);

        rv = aUri->GetAsciiHost(hostName);
        NS_ENSURE_SUCCESS(rv,rv);
    }
    else 
    {
        // step 2, set the uri's hostName and the local variable hostName
        // to be the host name of the server we found
        nsXPIDLCString hostBuf;
        rv = server->GetHostName(getter_Copies(hostBuf));
        NS_ENSURE_SUCCESS(rv,rv);
        hostName = hostBuf;

        rv = aUri->SetHost(hostName);
        NS_ENSURE_SUCCESS(rv,rv);
    }
  }

  if (NS_FAILED(rv) || !server)
  {
    PRBool isSecure = PR_FALSE;
    if (PL_strcasecmp("snews",scheme.get()) == 0)
    {
      isSecure = PR_TRUE;
      if ((port == 0) || (port == -1)) 
          port = SECURE_NEWS_PORT;
    }
    rv = CreateNewsAccount(hostName.get(), isSecure, port, getter_AddRefs(server));
  }
   
  if (NS_FAILED(rv)) return rv;
  if (!server) return NS_ERROR_FAILURE;
  
  nntpServer = do_QueryInterface(server, &rv);

  if (!nntpServer || NS_FAILED(rv))
    return rv;

  nsCAutoString spec;
  rv = aUri->GetSpec(spec);
  NS_ENSURE_SUCCESS(rv,rv);

#if 0 // this not ready yet. 
  nsNewsAction action = nsINntpUrl::ActionUnknown;
  nsCOMPtr <nsINntpUrl> nntpUrl = do_QueryInterface(aUri);
  if (nntpUrl) {
    rv = nntpUrl->GetNewsAction(&action);
    NS_ENSURE_SUCCESS(rv,rv);
  }

  // if this is a news-message:/ uri, decompose it and set hasMsgOffline on the uri
  // Or, if it's of this form, we need to do the same.
  // "news://news.mozilla.org:119/3D612B96.1050301%40netscape.com?part=1.2&type=image/gif&filename=hp_icon_logo.gif"

  // XXX todo, or do we want to check if it is a news-message:// uri or
  // a news:// uri (but action is not a fetch related action?)
  if (!PL_strncmp(spec.get(), kNewsMessageRootURI, kNewsMessageRootURILen) ||
      (action == nsINntpUrl::ActionFetchPart || action == nsINntpUrl::ActionFetchArticle)) 
  {
#else
  // if this is a news-message:/ uri, decompose it and set hasMsgOffline on the uri
  if (!PL_strncmp(spec.get(), kNewsMessageRootURI, kNewsMessageRootURILen)) 
  {
#endif
    nsCOMPtr <nsIMsgFolder> folder;
    nsMsgKey key = nsMsgKey_None;
    rv = DecomposeNewsMessageURI(spec.get(), getter_AddRefs(folder), &key);
    if (NS_SUCCEEDED(rv) && folder)
    {
      PRBool hasMsgOffline = PR_FALSE;
      folder->HasMsgOffline(key, &hasMsgOffline);
      nsCOMPtr<nsIMsgMailNewsUrl> msgUrl (do_QueryInterface(aUri));
      if (msgUrl)
        msgUrl->SetMsgIsInLocalCache(hasMsgOffline);
    }
  }

  rv = nntpServer->GetNntpConnection(aUri, aMsgWindow, aProtocol);
  if (NS_FAILED(rv) || !*aProtocol) 
    return NS_ERROR_OUT_OF_MEMORY;
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgMessageService::GetUrlForUri ( in string  aMessageURI,
out nsIURI  aURL,
in nsIMsgWindow  aMsgWindow 
) [inherited]
void nsIContentHandler::handleContent ( in string  aContentType,
in nsIInterfaceRequestor  aWindowContext,
in nsIRequest  aRequest 
) [inherited]

Tells the content handler to take over handling the content.

If this function succeeds, the URI Loader will leave this request alone, ignoring progress notifications. Failure of this method will cause the request to be cancelled, unless the error code is NS_ERROR_WONT_HANDLE_CONTENT (see below).

Parameters:
aWindowContextWindow context, used to get things like the current nsIDOMWindow for this request. May be null.
aContentTypeThe content type of aRequest
aRequestA request whose content type is already known.
Exceptions:
NS_ERROR_WONT_HANDLE_CONTENTIndicates that this handler does not want to handle this content. A different way for handling this content should be tried.

now the the message datasource is going away we need away to go from message uri to go nsIMsgDBHdr

Constructs a new channel from the given URI for this protocol handler.

nsIURI nsIProtocolHandler::newURI ( in AUTF8String  aSpec,
in string  aOriginCharset,
in nsIURI  aBaseURI 
) [inherited]

Makes a URI object that is suitable for loading by this protocol, where the URI string is given as an UTF-8 string.

The caller may provide the charset from which the URI string originated, so that the URI string can be translated back to that charset (if necessary) before communicating with, for example, the origin server of the URI string. (Many servers do not support UTF-8 IRIs at the present time, so we must be careful about tracking the native charset of the origin server.)

Parameters:
aSpec- the URI string in UTF-8 encoding. depending on the protocol implementation, unicode character sequences may or may not be xx escaped.
aOriginCharset- the charset of the document from which this URI string originated. this corresponds to the charset that should be used when communicating this URI to an origin server, for example. if null, then UTF-8 encoding is assumed (i.e., no charset transformation from aSpec).
aBaseURI- if null, aSpec must specify an absolute URI. otherwise, aSpec may be resolved relative to aBaseURI, depending on the protocol. If the protocol has no concept of relative URI aBaseURI will simply be ignored.
void nsIMsgMessageService::openAttachment ( in string  aContentType,
in string  aFileName,
in string  aUrl,
in string  aMessageUri,
in nsISupports  aDisplayConsumer,
in nsIMsgWindow  aMsgWindow,
in nsIUrlListener  aUrlListener 
) [inherited]
nsIURI nsINntpService::postMessage ( in nsIFileSpec  fileToPost,
in string  newsgroupNames,
in string  aAccountKey,
in nsIUrlListener  aUrlListener,
in nsIMsgWindow  aMsgWindow 
) [inherited]
nsresult nsNntpService::RunNewsUrl ( nsIURI aUrl,
nsIMsgWindow aMsgWindow,
nsISupports *  aConsumer 
) [protected]

Definition at line 1256 of file nsNntpService.cpp.

{
  nsresult rv;

  if (WeAreOffline())
    return NS_MSG_ERROR_OFFLINE;

  // almost there...now create a nntp protocol instance to run the url in...
  nsCOMPtr <nsINNTPProtocol> nntpProtocol;
  rv = GetProtocolForUri(aUri, aMsgWindow, getter_AddRefs(nntpProtocol));

  if (NS_SUCCEEDED(rv))
    rv = nntpProtocol->Initialize(aUri, aMsgWindow);
  if (NS_FAILED(rv)) return rv;
  
  rv = nntpProtocol->LoadNewsUrl(aUri, aConsumer);
  return rv;
}

Here is the call graph for this function:

void nsIMsgMessageService::SaveMessageToDisk ( in string  aMessageURI,
in nsIFileSpec  aFile,
in boolean  aGenerateDummyEnvelope,
in nsIUrlListener  aUrlListener,
out nsIURI  aURL,
in boolean  canonicalLineEnding,
in nsIMsgWindow  aMsgWindow 
) [inherited]
void nsIMsgMessageService::Search ( in nsIMsgSearchSession  aSearchSession,
in nsIMsgWindow  aMsgWindow,
in nsIMsgFolder  aMsgFolder,
in string  aSearchUri 
) [inherited]
nsresult nsNntpService::SetUpNntpUrlForPosting ( const char *  aAccountKey,
char **  newsUrlSpec 
) [protected]

Definition at line 772 of file nsNntpService.cpp.

{
  nsresult rv = NS_OK;

  nsXPIDLCString host;
  PRInt32 port;

  nsCOMPtr<nsIMsgIncomingServer> nntpServer;
  rv = GetNntpServerByAccount(aAccountKey, getter_AddRefs(nntpServer));
  if (NS_SUCCEEDED(rv) && nntpServer)
  {
    nntpServer->GetRealHostName(getter_Copies(host));
    nntpServer->GetPort(&port);
  }

  *newsUrlSpec = PR_smprintf("%s/%s:%d",kNewsRootURI, host.IsEmpty() ? "news" : host.get(), port);
  if (!*newsUrlSpec) return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the call graph for this function:

nsIURI nsIMsgMessageService::streamMessage ( in string  aMessageURI,
in nsISupports  aConsumer,
in nsIMsgWindow  aMsgWindow,
in nsIUrlListener  aUrlListener,
in boolean  aConvertData,
in string  aAdditionalHeader 
) [inherited]
void nsINntpService::updateCounts ( in nsINntpIncomingServer  nntpServer,
in nsIMsgWindow  aMsgWindow 
) [inherited]

Definition at line 1243 of file nsNntpService.cpp.

{
       nsresult rv = NS_OK;
  PRBool offline = PR_FALSE;

  nsCOMPtr<nsIIOService> netService(do_GetService(kIOServiceCID, &rv));
  if (NS_SUCCEEDED(rv) && netService)
    netService->GetOffline(&offline);

  return offline;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

const unsigned long nsIProtocolHandler::ALLOWS_PROXY = (1<<2) [inherited]

This protocol handler can be proxied via a proxy (socks or http) (e.g., irc, smtp, http, etc.).

If the protocol supports transparent proxying, the handler should implement nsIProxiedProtocolHandler.

If it supports only HTTP proxying, then it need not support nsIProxiedProtocolHandler, but should instead set the ALLOWS_PROXY_HTTP flag (see below).

See also:
nsIProxiedProtocolHandler

Definition at line 148 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::ALLOWS_PROXY_HTTP = (1<<3) [inherited]

This protocol handler can be proxied using a http proxy (e.g., http, ftp, etc.).

nsIIOService::newChannelFromURI will feed URIs from this protocol handler to the HTTP protocol handler instead. This flag is ignored if ALLOWS_PROXY is not set.

Definition at line 156 of file nsIProtocolHandler.idl.

Definition at line 87 of file nsINntpService.idl.

can this type of server be removed from the account manager? for instance, local mail is not removable

Definition at line 80 of file nsIMsgProtocolInfo.idl.

can you duplicate this server? for instance, local mail is unique and should not be duplicated.

Definition at line 91 of file nsIMsgProtocolInfo.idl.

do messages arrive for this server if they do, we can use our junk controls on it.

Definition at line 114 of file nsIMsgProtocolInfo.idl.

An attribute that tell us whether on not we can get messages for the given server type this is poorly named right now.

it's really is there an inbox for this type? XXX todo, rename this.

Definition at line 108 of file nsIMsgProtocolInfo.idl.

can this type of server log in at startup?

Definition at line 85 of file nsIMsgProtocolInfo.idl.

do biff by default?

Definition at line 119 of file nsIMsgProtocolInfo.idl.

the default path to store local data for this type of server.

Each server is usually in a subdirectory below this

Definition at line 55 of file nsIMsgProtocolInfo.idl.

The default port is the port that this protocol normally uses.

If a port does not make sense for the protocol (e.g., "about:") then -1 will be returned.

Definition at line 61 of file nsIProtocolHandler.idl.

Definition at line 118 of file nsNntpService.h.

Definition at line 116 of file nsNntpService.h.

Definition at line 115 of file nsNntpService.h.

do we need to build special folder URIs ? In case of IMAP, special folders like 'Sent', 'Drafts' and 'Templates' are not created unless needed.

But, we do need to create folder URIs to reflect the choices in the UI in copies and folders settings panel.

Definition at line 132 of file nsIMsgProtocolInfo.idl.

if the pretty name of the server should just be the e-mail address.

Otherwise it usually ends up being something like "news on hostname"

Definition at line 74 of file nsIMsgProtocolInfo.idl.

readonly attribute unsigned long nsIProtocolHandler::protocolFlags [inherited]

Returns the protocol specific flags (see flag definitions below).

Definition at line 66 of file nsIProtocolHandler.idl.

does this server type require a username? for instance, news does not but IMAP/POP do

Definition at line 67 of file nsIMsgProtocolInfo.idl.

readonly attribute ACString nsIProtocolHandler::scheme [inherited]

The scheme of this protocol (e.g., "file").

Definition at line 54 of file nsIProtocolHandler.idl.

readonly attribute nsIIDPtr nsIMsgProtocolInfo::serverIID [inherited]

the IID of the protocol-specific interface for this server usually used from JS to dynamically get server-specific attributes

Definition at line 61 of file nsIMsgProtocolInfo.idl.

do we need to show compose message link in the AccountCentral page ?

Definition at line 124 of file nsIMsgProtocolInfo.idl.

do we allow special folder deletion ?

Definition at line 137 of file nsIMsgProtocolInfo.idl.

const unsigned long nsIProtocolHandler::URI_NOAUTH = (1<<1) [inherited]

no authority component (file, ...)

Definition at line 135 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::URI_NORELATIVE = (1<<0) [inherited]

no concept of relative URIs (about, javascript, finger, ...)

Definition at line 130 of file nsIProtocolHandler.idl.

const unsigned long nsIProtocolHandler::URI_STD = 0 [inherited]

standard full URI with authority component and concept of relative URIs (http, ftp, ...)

Definition at line 125 of file nsIProtocolHandler.idl.


The documentation for this class was generated from the following files: