From 8dd2642555f9a412064c6644e1c7435195d36aff Mon Sep 17 00:00:00 2001 From: Ben Reitman Date: Fri, 12 Jul 2019 10:26:29 -0400 Subject: [PATCH 1/4] committing changes to change branches --- packages/main/src/compose/edit.test.ts | 43 +++++++++++++++++++++++++ packages/main/src/compose/edit.ts | 6 ++++ packages/main/src/compose/reply.test.ts | 2 ++ packages/main/src/compose/reply.ts | 11 ++++++- 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/packages/main/src/compose/edit.test.ts b/packages/main/src/compose/edit.test.ts index ddbc9949..deda21fe 100644 --- a/packages/main/src/compose/edit.test.ts +++ b/packages/main/src/compose/edit.test.ts @@ -84,11 +84,50 @@ it("edits a message", () => { "" } } + ], + [ + "content-id", + { + value: "0337ae7e-c468-437d-b7e1-95dc7d9debb8@gmail.com" + } ] ] }) }) +it("guaruntees that edited messages have a Content-ID header", async () => { + // connectionManager = mockConnection(); + + const content = { + type: "text", + subtype: "plain", + content: "What I meant to say was, hello!" + } + const testMessage = testThread[1].attributes + const testPart = testMessage.struct![0] as imap.ImapMessagePart + const editedMessage = { + envelope_messageId: testMessage.envelope.messageId + } + const editedPart = { + content_id: testPart.id + } + const { partHeaders } = composeEdit({ + account, + content, + conversation: conversationFrom(testThread), + editedMessage, + editedPart, + resource: { + messageId: testMessage.envelope.messageId, + contentId: testPart.id + } + }) + + expect(partHeaders).toMatchObject({ + "3": expect.arrayContaining([["content-id", { value: testPart.id }]]) + }) +}) + function conversationFrom( messages: Array<{ attributes: MessageAttributes }> ): C.Conversation { @@ -97,3 +136,7 @@ function conversationFrom( } return cache.getThreads(accountId)[0] } + +afterEach(async () => { + db.prepare("delete from accounts").run() +}) diff --git a/packages/main/src/compose/edit.ts b/packages/main/src/compose/edit.ts index 8e081e50..ceb91d26 100644 --- a/packages/main/src/compose/edit.ts +++ b/packages/main/src/compose/edit.ts @@ -104,6 +104,12 @@ export function composeEdit({ resource: `<${midUri(resource.messageId, resource.contentId)}>` } } + ], + [ + "content-id", + { + value: editedPart.content_id + } ] ] }, diff --git a/packages/main/src/compose/reply.test.ts b/packages/main/src/compose/reply.test.ts index ad3e8bbe..7f7fd88a 100644 --- a/packages/main/src/compose/reply.test.ts +++ b/packages/main/src/compose/reply.test.ts @@ -9,6 +9,8 @@ let account: cache.Account let accountId: cache.ID let boxId: cache.ID +jest.mock("imap") + beforeEach(async () => { const { lastInsertRowid } = db .prepare("insert into accounts (email) values (?)") diff --git a/packages/main/src/compose/reply.ts b/packages/main/src/compose/reply.ts index 0613c760..7b010ba6 100644 --- a/packages/main/src/compose/reply.ts +++ b/packages/main/src/compose/reply.ts @@ -53,7 +53,16 @@ export function composeReply({ conversation.messages.map(m => m.envelope_messageId).filter(nonNull) ] ], - partHeaders: {}, + partHeaders: { + "1": [ + [ + "content-id", + { + value: "" + } + ] + ] + }, bodies: { "1": Buffer.from(content.content, "utf8") } } } From 24a826b8729015c0e7a411752db3ea52cbb9025f Mon Sep 17 00:00:00 2001 From: Ben Reitman Date: Fri, 12 Jul 2019 14:55:24 -0400 Subject: [PATCH 2/4] composed messages have a contentID --- packages/main/src/compose/edit.test.ts | 43 +++++++++++++----- packages/main/src/compose/edit.ts | 6 --- .../main/src/compose/newConversation.test.ts | 45 +++++++++++++++++++ packages/main/src/compose/reply.test.ts | 30 ++++++++++++- packages/main/src/compose/reply.ts | 11 +---- 5 files changed, 105 insertions(+), 30 deletions(-) create mode 100644 packages/main/src/compose/newConversation.test.ts diff --git a/packages/main/src/compose/edit.test.ts b/packages/main/src/compose/edit.test.ts index deda21fe..9a205c38 100644 --- a/packages/main/src/compose/edit.test.ts +++ b/packages/main/src/compose/edit.test.ts @@ -84,20 +84,12 @@ it("edits a message", () => { "" } } - ], - [ - "content-id", - { - value: "0337ae7e-c468-437d-b7e1-95dc7d9debb8@gmail.com" - } ] ] }) }) -it("guaruntees that edited messages have a Content-ID header", async () => { - // connectionManager = mockConnection(); - +it("has a Content-ID header", async () => { const content = { type: "text", subtype: "plain", @@ -111,7 +103,7 @@ it("guaruntees that edited messages have a Content-ID header", async () => { const editedPart = { content_id: testPart.id } - const { partHeaders } = composeEdit({ + const { attributes } = composeEdit({ account, content, conversation: conversationFrom(testThread), @@ -123,8 +115,35 @@ it("guaruntees that edited messages have a Content-ID header", async () => { } }) - expect(partHeaders).toMatchObject({ - "3": expect.arrayContaining([["content-id", { value: testPart.id }]]) + expect(attributes).toMatchObject({ + struct: [ + { + partID: "1", + type: "multipart", + subtype: "mixed", + params: {} + }, + [ + { + partID: "2", + type: "text", + subtype: "plain", + id: expect.any(String), + params: { charset: "UTF-8" }, + disposition: { type: "fallback" } + } + ], + [ + { + partID: "3", + type: content.type, + subtype: content.subtype, + id: expect.any(String), + params: { charset: "UTF-8" }, + disposition: { type: "replacement" } + } + ] + ] }) }) diff --git a/packages/main/src/compose/edit.ts b/packages/main/src/compose/edit.ts index ceb91d26..8e081e50 100644 --- a/packages/main/src/compose/edit.ts +++ b/packages/main/src/compose/edit.ts @@ -104,12 +104,6 @@ export function composeEdit({ resource: `<${midUri(resource.messageId, resource.contentId)}>` } } - ], - [ - "content-id", - { - value: editedPart.content_id - } ] ] }, diff --git a/packages/main/src/compose/newConversation.test.ts b/packages/main/src/compose/newConversation.test.ts new file mode 100644 index 00000000..5133194d --- /dev/null +++ b/packages/main/src/compose/newConversation.test.ts @@ -0,0 +1,45 @@ +import * as cache from "../cache" +import { inbox } from "../cache/testFixtures" +import db from "../db" +import { MessageInput } from "../generated/graphql" +import { composeNewConversation } from "./newConversation" + +let account: cache.Account +let accountId: cache.ID +let boxId: cache.ID + +beforeEach(async () => { + const { lastInsertRowid } = db + .prepare("insert into accounts (email) values (?)") + .run("jesse@sitr.us") + accountId = lastInsertRowid + account = cache.getAccount(accountId)! + boxId = cache.persistBoxState(accountId, inbox) +}) +describe("a message for a new Conversation", () => { + it("has a content-ID", async () => { + const message: MessageInput = { + subject: "testing", + to: [{ host: "test.com", mailbox: "ben", name: "Ben Reitman" }], + content: { + type: "text", + subtype: "plain", + content: "hey just testing" + } + } + + const { attributes } = composeNewConversation({ account, message }) + + expect(attributes).toMatchObject({ + struct: [ + { + id: expect.any(String), + partID: "1", + type: message.content.type, + subtype: message.content.subtype, + params: { charset: "UTF-8" } + } + ] + }) + }) +}) diff --git a/packages/main/src/compose/reply.test.ts b/packages/main/src/compose/reply.test.ts index 7f7fd88a..5d076316 100644 --- a/packages/main/src/compose/reply.test.ts +++ b/packages/main/src/compose/reply.test.ts @@ -9,8 +9,6 @@ let account: cache.Account let accountId: cache.ID let boxId: cache.ID -jest.mock("imap") - beforeEach(async () => { const { lastInsertRowid } = db .prepare("insert into accounts (email) values (?)") @@ -87,6 +85,34 @@ describe("reply recipients", () => { }) }) +describe("reply", () => { + it("has a Content-ID header", async () => { + const content = { + type: "text", + subtype: "plain", + content: "What I meant to say was, hello!" + } + + const { attributes } = composeReply({ + account, + content, + conversation: conversationFrom(testThread) + }) + + expect(attributes).toMatchObject({ + struct: [ + { + id: expect.any(String), + partID: "1", + type: content.type, + subtype: content.subtype, + params: { charset: "UTF-8" } + } + ] + }) + }) +}) + afterEach(() => { db.prepare("delete from accounts").run() }) diff --git a/packages/main/src/compose/reply.ts b/packages/main/src/compose/reply.ts index 7b010ba6..0613c760 100644 --- a/packages/main/src/compose/reply.ts +++ b/packages/main/src/compose/reply.ts @@ -53,16 +53,7 @@ export function composeReply({ conversation.messages.map(m => m.envelope_messageId).filter(nonNull) ] ], - partHeaders: { - "1": [ - [ - "content-id", - { - value: "" - } - ] - ] - }, + partHeaders: {}, bodies: { "1": Buffer.from(content.content, "utf8") } } } From 4200b96035ebd54864352b3937768b32ef00d5b9 Mon Sep 17 00:00:00 2001 From: Ben Reitman Date: Tue, 16 Jul 2019 10:31:05 -0400 Subject: [PATCH 3/4] fix tests with requested changes --- packages/main/src/compose/edit.test.ts | 14 +++---------- .../main/src/compose/newConversation.test.ts | 21 +++---------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/packages/main/src/compose/edit.test.ts b/packages/main/src/compose/edit.test.ts index 9a205c38..8c53e6d6 100644 --- a/packages/main/src/compose/edit.test.ts +++ b/packages/main/src/compose/edit.test.ts @@ -118,29 +118,21 @@ it("has a Content-ID header", async () => { expect(attributes).toMatchObject({ struct: [ { - partID: "1", type: "multipart", - subtype: "mixed", - params: {} + subtype: "mixed" }, [ { - partID: "2", type: "text", subtype: "plain", - id: expect.any(String), - params: { charset: "UTF-8" }, - disposition: { type: "fallback" } + id: expect.any(String) } ], [ { - partID: "3", type: content.type, subtype: content.subtype, - id: expect.any(String), - params: { charset: "UTF-8" }, - disposition: { type: "replacement" } + id: expect.any(String) } ] ] diff --git a/packages/main/src/compose/newConversation.test.ts b/packages/main/src/compose/newConversation.test.ts index 5133194d..5d9faa68 100644 --- a/packages/main/src/compose/newConversation.test.ts +++ b/packages/main/src/compose/newConversation.test.ts @@ -1,23 +1,10 @@ -import * as cache from "../cache" -import { inbox } from "../cache/testFixtures" -import db from "../db" import { MessageInput } from "../generated/graphql" import { composeNewConversation } from "./newConversation" -let account: cache.Account -let accountId: cache.ID -let boxId: cache.ID - -beforeEach(async () => { - const { lastInsertRowid } = db - .prepare("insert into accounts (email) values (?)") - .run("jesse@sitr.us") - accountId = lastInsertRowid - account = cache.getAccount(accountId)! - boxId = cache.persistBoxState(accountId, inbox) -}) describe("a message for a new Conversation", () => { it("has a content-ID", async () => { + const account = { email: "jesse@sitr.us", id: 1 } + const message: MessageInput = { subject: "testing", to: [{ host: "test.com", mailbox: "ben", name: "Ben Reitman" }], @@ -34,10 +21,8 @@ describe("a message for a new Conversation", () => { struct: [ { id: expect.any(String), - partID: "1", type: message.content.type, - subtype: message.content.subtype, - params: { charset: "UTF-8" } + subtype: message.content.subtype } ] }) From bc7538b1de649a2b5e353dfad9240d1cec05ed08 Mon Sep 17 00:00:00 2001 From: Ben Reitman Date: Wed, 17 Jul 2019 11:05:27 -0400 Subject: [PATCH 4/4] fix tests for updated edit --- packages/main/src/compose/edit.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/main/src/compose/edit.test.ts b/packages/main/src/compose/edit.test.ts index 951ba94d..a93857a0 100644 --- a/packages/main/src/compose/edit.test.ts +++ b/packages/main/src/compose/edit.test.ts @@ -100,11 +100,7 @@ it("has a Content-ID header", async () => { content, conversation: conversationFrom(testThread), editedMessage, - editedPart, - resource: { - messageId: testMessage.envelope.messageId, - contentId: testPart.id - } + editedPart }) expect(attributes).toMatchObject({