Skip to content

Commit

Permalink
Fix email parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh committed Sep 29, 2024
1 parent a4ce08a commit bed42d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 3 additions & 1 deletion aws/email-importer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export async function handler(event: ImporterEvent) {
Key: s3Record.s3.object.key,
});

const { highlights, volume } = await getHighlightsAndVolumeFromEmail(Body);
const email = (await Body?.transformToString("utf-8")) ?? "";

const { highlights, volume } = await getHighlightsAndVolumeFromEmail(email);

if (!volume) {
console.error("Volume is missing in the email");
Expand Down
7 changes: 2 additions & 5 deletions aws/email-importer/src/services/parsing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { GetObjectCommandOutput } from "@aws-sdk/client-s3";
import textToJSON from "highlights-email-to-json";
import kindleClippingsToJSON from "kindle-clippings-to-json";
import kindleEmailToJSON from "kindle-email-to-json";
Expand All @@ -18,7 +17,7 @@ export interface ParsedVolume {
title: string;
}

export type ParserFn = (mail: GetObjectCommandOutput["Body"]) => Promise<{
export type ParserFn = (mail: string) => Promise<{
highlights: ParsedHighlight[];
volume?: ParsedVolume;
}>;
Expand All @@ -33,9 +32,7 @@ const parsers: ParserFn[] = [
/**
* Run all parsers on the email body until one finds highlights
*/
export async function getHighlightsAndVolumeFromEmail(
email: GetObjectCommandOutput["Body"],
) {
export async function getHighlightsAndVolumeFromEmail(email: string) {
let highlights: ParsedHighlight[] = [];
let volume: ParsedVolume | undefined;

Expand Down

0 comments on commit bed42d9

Please sign in to comment.