summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/import/test/unit/test_outlook_settings.js
blob: 0f0313dcad219fb83d8987ff967550bd4082b654 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

/* import-globals-from resources/mock_windows_reg_factory.js */
load("resources/mock_windows_reg_factory.js");

function POP3Account() {}

POP3Account.prototype = {
  "Account Name": "POP3 Account Name",
  "POP3 Server": "pop.host.invalid",
  "POP3 User Name": "pop3user",
  "Leave Mail On Server": 1,
  "SMTP Server": "smtp.host.invalid",
  "SMTP Display Name": "SMTP Display Name",
  "SMTP Email Address": "pop3user@host.invalid",
  "SMTP Reply To Email Address": "pop3user@host.invalid",
  "SMTP Organization Name": "SMTP Organization Name",
  "SMTP User Name": "smtpuser",
};

function IMAPAccount() {}

IMAPAccount.prototype = {
  "Account Name": "IMAP Account Name",
  "IMAP Server": "imap.host.invalid",
  "IMAP User Name": "imapuser",
  "SMTP Server": "smtp.host.invalid",
  "SMTP Display Name": "SMTP Display Name",
  "SMTP Email Address": "imapuser@host.invalid",
  "SMTP Reply To Email Address": "imapuser@host.invalid",
  "SMTP Organization Name": "SMTP Organization Name",
  "SMTP User Name": "smtpuser",
};

/* Outlook 98 */
function Outlook98Registry(defaultAccount) {
  this._defaultAccount = defaultAccount;
}

Outlook98Registry.prototype = {
  get "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager"() {
    return {
      "Default Mail Account": "00000001",
      "00000001": this._defaultAccount,
    };
  },
};

/* Outlook 2003 - */
function Outlook2003Registry(defaultAccount) {
  this._defaultAccount = defaultAccount;
}

Outlook2003Registry.prototype = {
  get "Software\\Microsoft\\Office\\Outlook\\OMI Account Manager"() {
    return {
      "Default Mail Account": "00000001",
      "00000001": this._defaultAccount,
    };
  },
};

var expectedPop3Account = {
  incomingServer: {
    prettyName: "POP3 Account Name",
    type: "pop3",
    hostName: "pop.host.invalid",
    username: "pop3user",
    leaveMessagesOnServer: true,

    // These are account default values, not imported from Outlook.
    // They should probably be omitted, but the check functions in
    // import_helper.js expect to find them.
    deleteMailLeftOnServer: false,
    deleteByAgeFromServer: false,
    numDaysToLeaveOnServer: 7,
    port: 110,
    isSecure: false,
    authMethod: Ci.nsMsgAuthMethod.passwordCleartext,
    socketType: Ci.nsMsgSocketType.plain,
    doBiff: true,
    biffMinutes: 10,
  },
  identity: {
    fullName: "SMTP Display Name",
    email: "pop3user@host.invalid",
    replyTo: "pop3user@host.invalid",
    organization: "SMTP Organization Name",
  },
  smtpServer: {
    hostname: "smtp.host.invalid",
    username: "smtpuser",
    port: 0, // default port
    authMethod: Ci.nsMsgAuthMethod.passwordCleartext,
    socketType: Ci.nsMsgSocketType.plain,
  },
};

var expectedImapAccount = {
  incomingServer: {
    prettyName: "IMAP Account Name",
    type: "imap",
    hostName: "imap.host.invalid",
    username: "imapuser",

    // These are account default values, not imported from Outlook.
    // They should probably be omitted, but the check functions in
    // import_helper.js expect to find them.
    port: 143,
    isSecure: false,
    authMethod: Ci.nsMsgAuthMethod.passwordCleartext,
    socketType: Ci.nsMsgSocketType.plain,
    doBiff: true,
    biffMinutes: 10,
  },
  identity: {
    fullName: "SMTP Display Name",
    email: "imapuser@host.invalid",
    replyTo: "imapuser@host.invalid",
    organization: "SMTP Organization Name",
  },
  smtpServer: {
    hostname: "smtp.host.invalid",
    username: "smtpuser",
    port: 0, // default port
    authMethod: Ci.nsMsgAuthMethod.passwordCleartext,
    socketType: Ci.nsMsgSocketType.plain,
  },
};

function teardown() {
  for (let server of MailServices.smtp.servers) {
    MailServices.smtp.deleteServer(server);
  }

  teardown_mock_registry();
}

function _test(registry, expectedAccount) {
  try {
    setup_mock_registry(registry);
    new SettingsImportHelper(null, "Outlook", [expectedAccount]).beginImport();
  } catch (e) {
    teardown();
    do_throw(e);
  }
  teardown();
}

function run_test() {
  _test(new Outlook2003Registry(new POP3Account()), expectedPop3Account);
  _test(new Outlook2003Registry(new IMAPAccount()), expectedImapAccount);

  _test(new Outlook98Registry(new POP3Account()), expectedPop3Account);
  _test(new Outlook98Registry(new IMAPAccount()), expectedImapAccount);
}