summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/compose/test/unit/test_createRFC822Message.js
blob: 9502031484d40bc3ebef952110e5c09695741f8a (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
/* 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/. */

/**
 * Test createRFC822Message creates a mail file.
 */

var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");

let customSendListener = {
  ...copyListener,
  OnStopCopy() {},

  /**
   * Test a mail file is created and has correct content.
   */
  async onStopSending(msgId, status, msg, returnFile) {
    ok(returnFile.exists(), "createRFC822Message should create a mail file");
    let content = await IOUtils.read(returnFile.path);
    content = String.fromCharCode(...content);
    ok(
      content.includes("Subject: Test createRFC822Message\r\n"),
      "Mail file should contain correct subject line"
    );
    ok(
      content.includes(
        "createRFC822Message is used by nsImportService \xe4\xe9"
      ),
      "Mail file should contain correct body"
    );
    do_test_finished();
  },
};

/**
 * Call createRFC822Message, expect onStopSending to be called.
 */
add_task(async function testCreateRFC822Message() {
  let identity = getSmtpIdentity(
    "from@tinderbox.invalid",
    getBasicSmtpServer()
  );

  let fields = Cc[
    "@mozilla.org/messengercompose/composefields;1"
  ].createInstance(Ci.nsIMsgCompFields);
  fields.from = "Somebody <somebody@tinderbox.invalid>";
  fields.to = "Nobody <nobody@tinderbox.invalid>";
  fields.subject = "Test createRFC822Message";

  let msgSend = Cc["@mozilla.org/messengercompose/send;1"].createInstance(
    Ci.nsIMsgSend
  );
  msgSend.createRFC822Message(
    identity,
    fields,
    "text/plain",
    // The following parameter is the message body that can contain arbitrary
    // binary data, let's try some windows-1252 data (äé).
    "createRFC822Message is used by nsImportService \xe4\xe9",
    true, // isDraft
    [],
    [],
    customSendListener
  );
  do_test_pending();
});