summaryrefslogtreecommitdiffstats
path: root/mailnews/compose/src/nsSMTPProtocolHandler.js
blob: 9b9e3ead0eff5c109538434c08e5a7cf38646b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

var kNetworkProtocolCIDPrefix = "@mozilla.org/network/protocol;1?name=";
var nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;

function makeProtocolHandler(aProtocol, aDefaultPort, aClassID) {
  return {
    classID: Components.ID(aClassID),
    QueryInterface: XPCOMUtils.generateQI([nsIProtocolHandler]),

    scheme: aProtocol,
    defaultPort: aDefaultPort,
    protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
                   nsIProtocolHandler.URI_DANGEROUS_TO_LOAD |
      nsIProtocolHandler.URI_NON_PERSISTABLE |
      nsIProtocolHandler.ALLOWS_PROXY |
      nsIProtocolHandler.URI_FORBIDS_AUTOMATIC_DOCUMENT_REPLACEMENT,

    newURI: function (aSpec, aOriginCharset, aBaseURI) {
      var url = Components.classes["@mozilla.org/messengercompose/smtpurl;1"]
                          .createInstance(Components.interfaces.nsIURI);

      url.spec = aSpec;

      return url;
    },

    newChannel: function (aURI) {
      throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
    },

    newChannel2: function(aURI, aLoadInfo)
    {
      throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
    },

    allowPort: function (port, scheme) {
      return port == aDefaultPort;
    }
  };
}

function nsSMTPProtocolHandler() {}

nsSMTPProtocolHandler.prototype =
  makeProtocolHandler("smtp",
                      Components.interfaces.nsISmtpUrl.DEFAULT_SMTP_PORT,
                      "b14c2b67-8680-4c11-8d63-9403c7d4f757");

function nsSMTPSProtocolHandler() {}

nsSMTPSProtocolHandler.prototype =
  makeProtocolHandler("smtps",
                      Components.interfaces.nsISmtpUrl.DEFAULT_SMTPS_PORT,
                      "057d0997-9e3a-411e-b4ee-2602f53fe05f");

var components = [nsSMTPProtocolHandler, nsSMTPSProtocolHandler];
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);