-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove Circular ingestion from legacy email"
- Loading branch information
Showing
5 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,10 +39,41 @@ describe('getFromAddress', () => { | |
).toThrow('From address is missing') | ||
}) | ||
|
||
test("raises if the from address name does not contain ' via '", () => { | ||
expect(() => | ||
getFromAddress( | ||
parseFrom( | ||
'"Example <[email protected]>" <[email protected]>' | ||
) | ||
) | ||
).toThrow("Expected From name to contain ' via '") | ||
}) | ||
|
||
test('returns the address verbatim for a normal email address', () => { | ||
expect(getFromAddress(parseFrom('[email protected]'))).toEqual( | ||
'[email protected]' | ||
) | ||
expect(getFromAddress(parseFrom('[email protected]'))).toEqual({ | ||
address: '[email protected]', | ||
submittedHow: 'email', | ||
}) | ||
}) | ||
|
||
test('returns the original address for a rewritten address', () => { | ||
expect( | ||
getFromAddress( | ||
parseFrom( | ||
'"Example <[email protected]> via gcncirc" <[email protected]>' | ||
) | ||
) | ||
).toEqual({ address: '[email protected]', submittedHow: 'email-legacy' }) | ||
}) | ||
|
||
test('returns the original address for a rewritten address with an alternative "via" name', () => { | ||
expect( | ||
getFromAddress( | ||
parseFrom( | ||
'"Example <[email protected]> via my mind" <[email protected]>' | ||
) | ||
) | ||
).toEqual({ address: '[email protected]', submittedHow: 'email-legacy' }) | ||
}) | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ const fromName = 'GCN Circulars' | |
export const handler = createEmailIncomingMessageHandler( | ||
async ({ content }) => { | ||
const parsed = await parseEmailContentFromSource(content) | ||
const userEmail = getFromAddress(parsed.from) | ||
const { address: userEmail, submittedHow } = getFromAddress(parsed.from) | ||
const to = getReplyToAddresses(parsed.replyTo) ?? [userEmail] | ||
|
||
const userData = | ||
|
@@ -92,7 +92,7 @@ export const handler = createEmailIncomingMessageHandler( | |
body: parsed.text, | ||
sub: userData.sub, | ||
submitter: formatAuthor(userData), | ||
submittedHow: 'email', | ||
submittedHow, | ||
} | ||
|
||
const eventId = parseEventFromSubject(parsed.subject) | ||
|
@@ -204,7 +204,7 @@ If you have not already done so, we encourage you to make an account at ${origin | |
- Your Circulars settings have been transferred automatically. | ||
- You are able to submit Circulars from the same email addresses registered in the legacy service. | ||
- Emails from GCN come from a new address, no-reply@${hostname}. | ||
- We encourage you to submit Circulars to the new address, circulars@${hostname}. The old address, [email protected], has been retired. | ||
- We encourage you to submit Circulars to the new address, circulars@${hostname}. The old GCN Circulars submission address, [email protected], will be retired on December 31, 2024. | ||
- The new archive, ${origin}/circulars, includes all past Circulars. We have frozen the old archive, https://gcn.gsfc.nasa.gov/gcn3_archive.html. | ||
For more information about the GCN Circulars, please see ${origin}/circulars. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,43 @@ | |
*/ | ||
import type { AddressObject, Source } from 'mailparser' | ||
import { simpleParser } from 'mailparser' | ||
import addressparser from 'nodemailer/lib/addressparser' | ||
|
||
import type { SubmittedHow } from '~/routes/circulars/circulars.lib' | ||
|
||
const legacyAddress = '[email protected]' | ||
const legacyFromNameSplitter = ' via ' | ||
|
||
/** | ||
* Parse rewritten From addresses from capella2. | ||
* | ||
* Messages forwarded by capella2 from non-NASA addresses have From headers | ||
* that are rewritten like this: | ||
* | ||
* From: Albert Einstein <[email protected]> | ||
* --rewritten to-- | ||
* From: "Albert Einstein <[email protected]> via gcncirc" <[email protected]> | ||
* | ||
*/ | ||
export function getFromAddress(fromAddressObject?: AddressObject) { | ||
const from = fromAddressObject?.value[0] | ||
let from = fromAddressObject?.value[0] | ||
let submittedHow: SubmittedHow | ||
if (from?.address === legacyAddress) { | ||
const i = from.name.lastIndexOf(legacyFromNameSplitter) | ||
if (i === -1) | ||
throw new Error( | ||
`Expected From name to contain '${legacyFromNameSplitter}'` | ||
) | ||
from = addressparser(from.name.slice(0, i), { | ||
flatten: true, | ||
})[0] | ||
submittedHow = 'email-legacy' | ||
} else { | ||
submittedHow = 'email' | ||
} | ||
const address = from?.address | ||
if (!address) throw new Error('From address is missing') | ||
return address | ||
return { address, submittedHow } | ||
} | ||
|
||
export function getReplyToAddresses(replyTo?: AddressObject) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,4 +71,11 @@ To post a GCN Circular via the web form, simply go to the [GCN Circulars archive | |
|
||
### Post a GCN Circular by Email | ||
|
||
To submit a GCN Circular by email, send a message to <CircularsEmailAddress/>. | ||
To submit a GCN Circular by email, send a message to: <CircularsEmailAddress/>. | ||
|
||
The legacy address [email protected] forwards emails to <CircularsEmailAddress/>. This forwarding will be retired on December 31, 2024. Note that the new address is stricter than the old address about the `From:` address matching the sender. | ||
|
||
<Alert type="warning" headingLevel="h4"> | ||
**Do not send your Circular to both email addresses.** If you send it to both | ||
addresses, then it will be distributed twice as two different circulars. | ||
</Alert> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters