• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #12745

pending completion
#12745

push

circleci

web-flow
Merge pull request #2889 from mozilla/MNTOR-1039-Unsubscribe-endpoint

Opt-out mechanism for emails

282 of 1415 branches covered (19.93%)

Branch coverage included in aggregate %.

82 of 82 new or added lines in 9 files covered. (100.0%)

959 of 3901 relevant lines covered (24.58%)

2.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/views/emails/email-2022.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import AppConstants from '../../app-constants.js'
6
import { getMessage } from '../../utils/fluent.js'
7

8
const companyAddress = '2 Harrison St. #175, San Francisco, California 94105 USA'
×
9
const links = (data) => ({
×
10
  faq: 'https://support.mozilla.org/kb/firefox-monitor-faq',
11
  hibp: 'https://haveibeenpwned.com/',
12
  legal: `https://www.mozilla.org/about/legal?utm_source=fx-monitor&utm_medium=email&utm_campaign=${data.utmCampaign}&utm_content=email-footer-link`,
13
  termsAndPrivacy: `https://www.mozilla.org/privacy/firefox-monitor?utm_source=fx-monitor&utm_medium=email&utm_campaign=${data.utmCampaign}&utm_content=email-footer-link`
14
})
15

16
const images = {
×
17
  header: `${AppConstants.SERVER_URL}/images/email/person-at-desk.png`,
18
  footer: `${AppConstants.SERVER_URL}/images/email/mozilla-logo-bw.png`,
19
  logoDark: `${AppConstants.SERVER_URL}/images/email/monitor-logo-transparent-dark-mode.png`,
20
  logoLight: `${AppConstants.SERVER_URL}/images/email/monitor-logo-bg-light.png`
21
}
22

23
const bodyStyle = `
×
24
  color: black;
25
  font: normal 16px/1.2 sans-serif;
26
`
27

28
const tableStyle = `
×
29
  margin: auto;
30
  max-width: 1080px;
31
  text-align: center;
32
  width: 100%;
33
`
34

35
const headerTableStyle = `
×
36
  background-color: #321c64;
37
  color: white;
38
  height: 331px;
39
  text-align: left;
40
  width: 100%;
41
`
42

43
const headerImageContainerStyle = `
×
44
  background-color: #321c64;
45
  vertical-align: bottom;
46
  width: 50%;
47
`
48

49
const headerImageStyle = `
×
50
  display: block;
51
  margin-left: auto;
52
  max-width: 100%;
53
  object-fit: cover;
54
  object-position: left;
55
`
56

57
const footerContainerStyle = `
×
58
  background: #f9f9fa;
59
  border-top: 1px solid #dddddd;
60
  padding: 24px 0;
61
`
62

63
const footerImageStyle = `
×
64
  display: block;
65
  margin: 24px auto 0;
66
`
67

68
const emailHeader = (data) => `
×
69
  <tr class='logo'>
70
    <td height='100'></td>
71
  </tr>
72
  <tr class='header'>
73
    <td>
74
      <table
75
        border='0'
76
        cellpadding='0'
77
        cellspacing='0'
78
        role='presentation'
79
        style='${headerTableStyle}'
80
      >
81
        <tr>
82
          <td>
83
            <h1>
84
              ${getMessage(data.heading)}
85
            </h1>
86
            ${data.subhead !== ''
×
87
              ? `<p>${getMessage(data.subhead)}</p>`
88
              : ''
89
            }
90
          </td>
91
          <td
92
            class='header-image'
93
            style='${headerImageContainerStyle}'
94
          >
95
            <img
96
              alt=''
97
              height='331'
98
              src='${images.header}'
99
              style='${headerImageStyle}'
100
              width='476'
101
            >
102
          </td>
103
        </tr>
104
      </table>
105
    </td>
106
  </tr>
107
`
108

109
function getUnsubscribeCopy (data) {
110
  const unsubLink = `
×
111
    <a href='${data.unsubscribeUrl}'>
112
      ${getMessage('email-unsub-link')}
113
    </a>
114
  `
115
  const faqLink = `
×
116
    <a href='${links(data).faq}'>${getMessage('frequently-asked-questions')}</a>
117
  `
118

119
  return getMessage('email-footer-blurb', {
×
120
    unsubLink,
121
    faqLink
122
  })
123
}
124

125
const emailFooter = (data) => `
×
126
  <tr class='footer'>
127
    <td style='${footerContainerStyle}'>
128
      ${
129
        data.unsubscribeUrl
×
130
          ? `<p>${getUnsubscribeCopy(data)}</p>`
131
          : ''
132
      }
133
      <p>
134
        ${getMessage('email-2022-hibp-attribution', {
135
          'hibp-link-attr': `href='${links(data).hibp}' rel='noopener'`
136
        })}
137
      </p>
138
      <img
139
        alt='${getMessage('mozilla')}'
140
        src='${images.footer}'
141
        style='${footerImageStyle}'
142
        width='130px'
143
      >
144
      <p>
145
        ${companyAddress}
146
      </p>
147
      <p>
148
        <a href='${links(data).legal}'>
149
          ${getMessage('legal')}
150
        </a>
151
        ${' • '}
152
        <a href='${links(data).termsAndPrivacy}'>
153
          ${getMessage('terms-and-privacy')}
154
        </a>
155
      </p>
156
    </td>
157
  </tr>
158
`
159

160
const getStyles = () => `
×
161
  <style>
162
    .email-body,
163
    .email-body * {
164
      margin: 0;
165
      padding: 0;
166
    }
167

168
    body.email-body,
169
    .email-container {
170
      color: black;
171
      font: normal 16px/1.2 sans-serif;
172
    }
173

174
    .email-container h1,
175
    .email-container p {
176
      margin: 12px auto;
177
      max-width: 600px;
178
      padding: 0 24px;
179
    }
180

181
    .email-container a {
182
      color: #592acb;
183
      text-decoration: none;
184
    }
185

186
    .email-container table {
187
      table-layout: fixed;
188
    }
189

190
    .email-container .logo > td {
191
      height: 100px;
192
      background-color: #f9f9fa;
193
      background-position: 50%;
194
      background-image: url('${images.logoLight}');
195
      background-repeat: no-repeat;
196
      background-size: 240px 50px;
197
      width: 100%;
198
    }
199

200
    @media screen and (max-width:600px) {
201
      .email-container .header-image {
202
        display: none;
203
      }
204
    }
205

206
    @media (prefers-color-scheme: dark) {
207
      .email-container .logo > td {
208
        background-image: url('${images.logoDark}')
209
      }
210
    }
211
  </style>
212
`
213

214
const getEmailContent = (data, partial) => {
×
215
  return `
×
216
    <table
217
      border='0'
218
      class='email-container'
219
      cellpadding='0'
220
      cellspacing='0'
221
      role='presentation'
222
      style='${tableStyle}'
223
    >
224
      ${emailHeader({
225
        heading: data.heading,
226
        subhead: data.subheading ?? ''
×
227
      })}
228
      ${partial(data)}
229
      ${emailFooter(data)}
230
    </table>
231
  `
232
}
233

234
const getPreviewTemplate = (data, partial) => `
×
235
  ${getStyles()}
236
  ${getEmailContent(data, partial)}
237
`
238

239
const getTemplate = (data, partial) => {
×
240
  return `
×
241
    <!doctype html>
242
    <html>
243
      <head>
244
        <meta name='viewport' content='width=device-width, initial-scale=1.0' />
245
        <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
246

247
        <title>
248
          ${getMessage('brand-fx-monitor')}
249
        </title>
250

251
        ${getStyles()}
252
      </head>
253

254
      <body class='email-body' style='${bodyStyle}'>
255
        ${getEmailContent(data, partial)}
256
      </body>
257
    </html>
258
  `
259
}
260

261
export { getPreviewTemplate, getTemplate }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc