MCPcopy
hub / github.com/mailvelope/mailvelope / onSecureBtn

Method onSecureBtn

src/controller/gmail.controller.js:118–174  ·  view source on GitHub ↗
({type, msgId, all, userInfo})

Source from the content-addressed store, hash-verified

116 }
117
118 async onSecureBtn({type, msgId, all, userInfo}) {
119 try {
120 const accessToken = await this.getAccessToken(userInfo);
121 const userEmail = userInfo.email;
122 const {threadId, internalDate, payload} = await gmail.getMessage({msgId, email: userEmail, accessToken});
123 const messageText = await gmail.extractMailBody({payload, userEmail, msgId, accessToken});
124 let subject = gmail.extractMailHeader(payload, 'Subject');
125 const {email: sender, name: senderName} = parseAddress(gmail.extractMailHeader(payload, 'From'));
126
127 const recipientsTo = [];
128 const recipientsCc = [];
129 const toList = parseAddressList(gmail.extractMailHeader(payload, 'To'));
130 const ccList = parseAddressList(gmail.extractMailHeader(payload, 'Cc'));
131 let attachments = [];
132 let quotedMailHeader;
133 if (type === 'reply') {
134 subject = `Re: ${subject}`;
135 recipientsTo.push(sender);
136 if (all) {
137 for (const {email} of toList) {
138 if (email !== sender && email !== userEmail) {
139 recipientsTo.push(email);
140 }
141 }
142 for (const {email} of ccList) {
143 if (email !== sender && email !== userEmail) {
144 recipientsCc.push(email);
145 }
146 }
147 }
148 quotedMailHeader = l10n.get('gmail_integration_quoted_mail_header_reply', [l10n.localizeDateTime(new Date(parseInt(internalDate, 10)), {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'}), `${senderName} <${sender}>`.trim()]);
149 } else {
150 subject = `Fwd: ${subject}`;
151 quotedMailHeader = l10n.get('gmail_integration_quoted_mail_header_forward', [`${senderName} <${sender}>`.trim(), l10n.localizeDateTime(new Date(parseInt(internalDate, 10)), {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit'}), subject, toList.map(({name, email}) => `${name} <${email}>`.trim()).join(', ')]);
152 if (ccList.length) {
153 quotedMailHeader += `\n${l10n.get('editor_label_copy_recipient')}: ${ccList.map(({name, email}) => `${name} <${email}>`.trim()).join(', ')}`;
154 }
155 quotedMailHeader += '\n';
156 attachments = await gmail.getMailAttachments({payload, userEmail, msgId, accessToken});
157 }
158 const options = {
159 userInfo,
160 subject,
161 recipientsTo,
162 recipientsCc,
163 threadId,
164 quotedMailHeader,
165 quotedMail: messageText || '',
166 quotedMailIndent: type === 'reply',
167 attachments,
168 keepAttachments: type !== 'reply'
169 };
170 this.onOpenEditor(options);
171 } catch (error) {
172 console.log(`Gmail API error: ${error.message}`);
173 }
174 }
175

Callers

nothing calls this directly

Calls 6

getAccessTokenMethod · 0.95
onOpenEditorMethod · 0.95
parseAddressFunction · 0.90
parseAddressListFunction · 0.90
pushMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected