summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/prefs/content/aw-incoming.js
blob: a4f746d71dd7b45663c36b4d10023fb8297878c3 (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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

/* import-globals-from AccountWizard.js */

var { cleanUpHostName, isLegalHostNameOrIP } = ChromeUtils.import(
  "resource:///modules/hostnameUtils.jsm"
);
var { NntpUtils } = ChromeUtils.import("resource:///modules/NntpUtils.jsm");

function incomingPageValidate() {
  let hostName = cleanUpHostName(document.getElementById("newsServer").value);

  let hasAccount = false;
  let server = NntpUtils.findServer(hostName);
  if (server) {
    // It's OK if a server exists, as long as it's not used by any account.
    hasAccount = MailServices.accounts.FindAccountForServer(server);
  }
  // Can advance if it's a legal host name and we do not already have a server
  // in use with the same host name.
  document.querySelector("wizard").canAdvance =
    !!isLegalHostNameOrIP(hostName) && !hasAccount;
}

function incomingPageUnload() {
  parent.GetPageData().hostname = cleanUpHostName(
    document.getElementById("newsServer").value
  );

  return true;
}

function incomingPageInit() {
  var pageData = parent.GetPageData();
  if (pageData.hostname) {
    document.getElementById("newsServer").value = pageData.hostname;
  }
  incomingPageValidate();
}