summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/base/src/MailChannel.sys.mjs
blob: a5fbf9ee75315f1b574f5e21c3dbe2babe8c8ebf (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
/* 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/. */

/**
 * @see {nsIMailChannel}
 */
export class MailChannel {
  _headerNames = [];
  _headerValues = [];
  _attachments = [];
  _mailCharacterSet = null;
  _progressListener = null;

  addHeaderFromMIME(name, value) {
    this._headerNames.push(name);
    this._headerValues.push(value);
  }

  get headerNames() {
    return this._headerNames;
  }

  get headerValues() {
    return this._headerValues;
  }

  handleAttachmentFromMIME(contentType, url, displayName, uri, notDownloaded) {
    let attachment = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
      Ci.nsIWritablePropertyBag2
    );
    attachment.setPropertyAsAUTF8String("contentType", contentType);
    attachment.setPropertyAsAUTF8String("url", url);
    attachment.setPropertyAsAUTF8String("displayName", displayName);
    attachment.setPropertyAsAUTF8String("uri", uri);
    attachment.setPropertyAsBool("notDownloaded", notDownloaded);
    this._attachments.push(attachment);
  }

  addAttachmentFieldFromMIME(field, value) {
    let attachment = this._attachments[this._attachments.length - 1];
    attachment.setPropertyAsAUTF8String(field, value);
  }

  get attachments() {
    return this._attachments.slice();
  }

  get mailCharacterSet() {
    return this._mailCharacterSet;
  }

  set mailCharacterSet(value) {
    let ccm = Cc["@mozilla.org/charset-converter-manager;1"].getService(
      Ci.nsICharsetConverterManager
    );
    this._mailCharacterSet = ccm.getCharsetAlias(value);
  }

  imipMethod = null;
  imipItem = null;
  smimeHeaderSink = null;

  get listener() {
    return this._progressListener?.get();
  }

  set listener(listener) {
    this._progressListener = Cu.getWeakReference(listener);
  }
}