Skip to content

Commit

Permalink
Merge pull request #2660 from lpsinger/remove-legacy-email-forwarding
Browse files Browse the repository at this point in the history
Remove Circular ingestion from legacy email
  • Loading branch information
dakota002 authored Dec 13, 2024
2 parents 909af08 + 489723d commit bf4e0b6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 83 deletions.
37 changes: 3 additions & 34 deletions app/email-incoming/circulars/__tests__/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,10 @@ 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({
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' })
expect(getFromAddress(parseFrom('[email protected]'))).toEqual(
'[email protected]'
)
})
})

Expand Down
6 changes: 3 additions & 3 deletions app/email-incoming/circulars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const fromName = 'GCN Circulars'
export const handler = createEmailIncomingMessageHandler(
async ({ content }) => {
const parsed = await parseEmailContentFromSource(content)
const { address: userEmail, submittedHow } = getFromAddress(parsed.from)
const userEmail = getFromAddress(parsed.from)
const to = getReplyToAddresses(parsed.replyTo) ?? [userEmail]

const userData =
Expand Down Expand Up @@ -92,7 +92,7 @@ export const handler = createEmailIncomingMessageHandler(
body: parsed.text,
sub: userData.sub,
submitter: formatAuthor(userData),
submittedHow,
submittedHow: 'email',
}

const eventId = parseEventFromSubject(parsed.subject)
Expand Down Expand Up @@ -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 GCN Circulars submission address, [email protected], will be retired on December 31, 2024.
- We encourage you to submit Circulars to the new address, circulars@${hostname}. The old address, [email protected], has been retired.
- 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.
Expand Down
35 changes: 2 additions & 33 deletions app/email-incoming/circulars/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,12 @@
*/
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) {
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 from = fromAddressObject?.value[0]
const address = from?.address
if (!address) throw new Error('From address is missing')
return { address, submittedHow }
return address
}

export function getReplyToAddresses(replyTo?: AddressObject) {
Expand Down
9 changes: 1 addition & 8 deletions app/routes/docs.circulars.submitting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,4 @@ 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/>.

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>
To submit a GCN Circular by email, send a message to <CircularsEmailAddress/>.
6 changes: 1 addition & 5 deletions app/routes/docs.contributing.email/route.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that each flow chart represents the email processing for a single one of GC

<img src={circularsIngestionImg} alt="Flow chart of GCN Circulars ingestion" />

Authorized GCN users can [submit GCN Circulars](/docs/circulars/submitting) in any one of three ways: by logging in and completing the [Web form](/circulars/new), by submitting an email to circulars@<i>stage</i>.gcn.nasa.gov, or by submitting an email to the legacy GCN Classic server at <span>gcncirc</span>@capella2.gsfc.nasa.gov.
Authorized GCN users can [submit GCN Circulars](/docs/circulars/submitting) in either of two ways: by logging in and completing the [Web form](/circulars/new) or by submitting an email to circulars@<i>stage</i>.gcn.nasa.gov.

### By Web form

Expand All @@ -36,10 +36,6 @@ To submit a Circular via email, the user sends an email to circulars@<i>stage</i
- The Lambda checks that the subject validates against a list of [allowed and disallowed keywords](/docs/circulars/styleguide#message-content).
- If all of the above checks pass, then the Circular is accepted, stored in the database, and distributed to GCN Circulars subscribers.

### By email to <span>gcncirc</span>@capella2.gsfc.nasa.gov

The legacy, on-premise GCN Classic server at NASA Goddard Space Flight Center, capella2.gsfc.nasa.gov, is configured to forward messages addressed to <span>gcncirc</span>@capella2.gsfc.nasa.gov to <span>circulars</span>@gcn.nasa.gov. Once received by Amazon SES, processing proceeds the same as above.

## Support Requests

**Source code:** [app/email-incoming/support](https://github.com/nasa-gcn/gcn.nasa.gov/tree/main/app/email-incoming/support)
Expand Down

0 comments on commit bf4e0b6

Please sign in to comment.