Skip to content

Including the body of the message when forwarding emails from Mail client. #195

Merged
elie222 merged 1 commit intoelie222:mainfrom
varuntree:forward_body
Jul 9, 2024
Merged

Including the body of the message when forwarding emails from Mail client. #195
elie222 merged 1 commit intoelie222:mainfrom
varuntree:forward_body

Conversation

@varuntree
Copy link

@varuntree varuntree commented Jun 28, 2024

As there is no api yet from the google's side to forward a message, we created our own method.
Tried, not to change and add to much of the complexity to the existing code.

for_image_test

Also added the Forwaded meta text for mail body.

Resolves #161

Summary by CodeRabbit

  • New Features

    • Enhanced email composition with new fields messageText and messageHtml for replies and forwards.
  • Refactor

    • Improved code modularity and readability in email composition by adding prepareReplyingToEmail and prepareForwardingEmail functions.
  • Style

    • Minor CSS adjustments for better UI consistency in email composition form.

@vercel
Copy link

vercel bot commented Jun 28, 2024

Someone is attempting to deploy a commit to the Inbox Zero Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


varuntree seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

The recent modifications enhance the email composition functionality, particularly for replying and forwarding emails. By introducing new fields in the ReplyingToEmail type, updating the ComposeEmailForm component to handle these fields, and adding helper functions for preparing email data in EmailPanel.tsx, these changes boost the modularity, readability, and efficiency of the codebase.

Changes

File Path Change Summary
apps/web/app/(app)/compose/ComposeEmailForm.tsx Added messageText and messageHtml fields to ReplyingToEmail; Modified onSubmit function to concatenate message content; Adjusted CSS classes.
apps/web/components/email-list/EmailPanel.tsx Introduced prepareReplyingToEmail and prepareForwardingEmail functions to improve modularity and readability of email handling logic.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant EmailPanel
  participant ComposeEmailForm

  User ->> EmailPanel: Initiates Reply/Forward
  EmailPanel ->> EmailPanel: Calls prepareReplyingToEmail or prepareForwardingEmail
  EmailPanel ->> ComposeEmailForm: Passes prepared email data
  ComposeEmailForm ->> ComposeEmailForm: Concatenates messageText and messageHtml
  User ->> ComposeEmailForm: Submits email form
  ComposeEmailForm ->> EmailPanel: Sends email data for processing
Loading

Poem

In the code forest, changes bloom so bright,
Emails now reply and forward with delight.
New fields added and functions clear,
Send messages with a hop and cheer!
🌸📬✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54e3500 and 93f4059.

Files selected for processing (2)
  • apps/web/app/(app)/compose/ComposeEmailForm.tsx (3 hunks)
  • apps/web/components/email-list/EmailPanel.tsx (3 hunks)
Additional context used
Biome
apps/web/components/email-list/EmailPanel.tsx

[error] 59-59: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 100-100: Using the role attribute 'list' on the 'ul' element is redundant, because it is implied by the semantic 'ul' element.

Unsafe fix: Remove the role attribute.

(lint/a11y/noRedundantRoles)


[error] 132-132: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 133-133: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 144-144: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 282-285: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 291-291: Provide a title attribute when using iframe elements.

Screen readers rely on the title set on an iframe to describe the content being displayed.

(lint/a11y/useIframeTitle)


[error] 15-16: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/app/(app)/compose/ComposeEmailForm.tsx

[error] 100-100: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 102-102: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 107-107: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 241-241: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 306-306: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 318-318: Do not use template literals if interpolation and special-character handling are not needed.

Unsafe fix: Replace with string literal

(lint/style/noUnusedTemplateLiteral)


[error] 85-85: This hook does not specify all of its dependencies: props.replyingToEmail?.messageHtml

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)


[error] 85-85: This hook does not specify all of its dependencies: props.replyingToEmail?.messageText

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)


[error] 87-87: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)


[error] 151-151: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

Additional comments not posted (3)
apps/web/components/email-list/EmailPanel.tsx (1)

16-16: Approved the addition of the ParsedMessage import.

The import is used effectively in the newly added functions prepareReplyingToEmail and prepareForwardingEmail.

Tools
Biome

[error] 15-16: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the transpilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

apps/web/app/(app)/compose/ComposeEmailForm.tsx (2)

51-52: Approved the addition of messageText and messageHtml fields to ReplyingToEmail.

These fields are essential for the new feature of including message bodies when replying or forwarding emails.


87-92: Avoid reassigning function parameters and address hook dependency issues.

Reassigning parameters can lead to confusing and hard-to-track bugs. Also, ensure that all dependencies are specified in the hook dependency list.

- data = {
+ const updatedData = {
    ...data,
    messageText: data.messageText + props.replyingToEmail?.messageText,
    messageHtml: (data.messageHtml ?? "") + (props.replyingToEmail?.messageHtml ?? ""),
};
+ await sendEmail(updatedData);
- const res = await postRequest<SendEmailResponse, SendEmailBody>("/api/google/messages/send", data);
+ const res = await postRequest<SendEmailResponse, SendEmailBody>("/api/google/messages/send", updatedData);
Tools
Biome

[error] 87-87: Reassigning a function parameter is confusing.

The parameter is declared here:

Use a local variable instead.

(lint/style/noParameterAssign)

Comment on lines +129 to +138
const prepareReplyingToEmail = (message: ParsedMessage) => ({
to: message.headers.from,
subject: `Re: ${message.headers.subject}`,
headerMessageId: message.headers["message-id"]!,
threadId: message.threadId!,
cc: message.headers.cc,
references: message.headers.references,
messageText: "",
messageHtml: "",
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling potential null values instead of using non-null assertions.

The use of non-null assertions (!) could lead to runtime errors if the properties are actually null.

- headerMessageId: message.headers["message-id"]!,
- threadId: message.threadId!,
+ headerMessageId: message.headers["message-id"] || 'default-message-id',
+ threadId: message.threadId || 'default-thread-id',
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const prepareReplyingToEmail = (message: ParsedMessage) => ({
to: message.headers.from,
subject: `Re: ${message.headers.subject}`,
headerMessageId: message.headers["message-id"]!,
threadId: message.threadId!,
cc: message.headers.cc,
references: message.headers.references,
messageText: "",
messageHtml: "",
});
const prepareReplyingToEmail = (message: ParsedMessage) => ({
to: message.headers.from,
subject: `Re: ${message.headers.subject}`,
headerMessageId: message.headers["message-id"] || 'default-message-id',
threadId: message.threadId || 'default-thread-id',
cc: message.headers.cc,
references: message.headers.references,
messageText: "",
messageHtml: "",
});
Tools
Biome

[error] 132-132: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 133-133: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

Comment on lines +140 to +166
const prepareForwardingEmail = (message: ParsedMessage) => ({
to: "",
subject: `Fwd: ${message.headers.subject}`,
headerMessageId: "",
threadId: message.threadId!,
cc: "",
references: "",
messageText: `
\n\n--- Forwarded message ---
\nFrom: ${message.headers.from}
\nDate: ${message.headers.date}
\nSubject: ${message.headers.subject}
\nTo: ${message.headers.to}
${message.textPlain}
`,
messageHtml: `
<br><br>
<div style="border-left: 2px solid #ccc; padding-left: 10px; margin: 10px 0;">
<p><strong>--- Forwarded message ---</strong></p>
<p><strong>From:</strong> ${message.headers.from}</p>
<p><strong>Date:</strong> ${message.headers.date}</p>
<p><strong>Subject:</strong> ${message.headers.subject}</p>
<p><strong>To:</strong> ${message.headers.to}</p>
</div>
${message.textHtml}
`,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling potential null values instead of using non-null assertions.

Similar to prepareReplyingToEmail, this function also uses non-null assertions that could lead to runtime errors. Additionally, ensure the template literals are necessary for the context, as they introduce potential XSS vulnerabilities.

- threadId: message.threadId!,
+ threadId: message.threadId || 'default-thread-id',
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const prepareForwardingEmail = (message: ParsedMessage) => ({
to: "",
subject: `Fwd: ${message.headers.subject}`,
headerMessageId: "",
threadId: message.threadId!,
cc: "",
references: "",
messageText: `
\n\n--- Forwarded message ---
\nFrom: ${message.headers.from}
\nDate: ${message.headers.date}
\nSubject: ${message.headers.subject}
\nTo: ${message.headers.to}
${message.textPlain}
`,
messageHtml: `
<br><br>
<div style="border-left: 2px solid #ccc; padding-left: 10px; margin: 10px 0;">
<p><strong>--- Forwarded message ---</strong></p>
<p><strong>From:</strong> ${message.headers.from}</p>
<p><strong>Date:</strong> ${message.headers.date}</p>
<p><strong>Subject:</strong> ${message.headers.subject}</p>
<p><strong>To:</strong> ${message.headers.to}</p>
</div>
${message.textHtml}
`,
});
const prepareForwardingEmail = (message: ParsedMessage) => ({
to: "",
subject: `Fwd: ${message.headers.subject}`,
headerMessageId: "",
threadId: message.threadId || 'default-thread-id',
cc: "",
references: "",
messageText: `
\n\n--- Forwarded message ---
\nFrom: ${message.headers.from}
\nDate: ${message.headers.date}
\nSubject: ${message.headers.subject}
\nTo: ${message.headers.to}
${message.textPlain}
`,
messageHtml: `
<br><br>
<div style="border-left: 2px solid #ccc; padding-left: 10px; margin: 10px 0;">
<p><strong>--- Forwarded message ---</strong></p>
<p><strong>From:</strong> ${message.headers.from}</p>
<p><strong>Date:</strong> ${message.headers.date}</p>
<p><strong>Subject:</strong> ${message.headers.subject}</p>
<p><strong>To:</strong> ${message.headers.to}</p>
</div>
${message.textHtml}
`,
});
Tools
Biome

[error] 144-144: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

messageHtml: "",
});

const prepareForwardingEmail = (message: ParsedMessage) => ({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, wondering if we need the same code on the backend when we forward an email?

As there are emails that are forwarded solely via the backend so the logic would be the same thing

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can use the same code, or maybe it even makes more sense if we just use it only in backend.
But, i can't find where exactly we forward the mails solely via backend, can you refer me there?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll take a look and share

@elie222
Copy link
Owner

elie222 commented Jul 8, 2024

@varuntree could you sign the CLA please (in the checks)

@varuntree
Copy link
Author

@elie222 Hey, i did signed already, but for some reason its not updated, check all the sources.
image

@elie222
Copy link
Owner

elie222 commented Jul 9, 2024

Merged.

The code where we had something similar already is here:
apps/web/utils/gmail/mail.ts:

  const raw = await createRawMailMessage({
    to: options.to,
    cc: options.cc,
    bcc: options.bcc,
    subject: `Fwd: ${message.headers.subject}`,
    messageText: `${options.content ?? ""}
        
---------- Forwarded message ----------
From: ${message.headers.from}
Date: ${message.headers.date}
Subject: ${message.headers.subject}
To: <${message.headers.to}>

${message.textPlain}`,
    messageHtml: `<div>${options.content ?? ""}</div>

<div>---------- Forwarded message ----------</div>
<div>From: ${message.headers.from}</div>
<div>Date: ${message.headers.date}</div>
<div>Subject: ${message.headers.subject}</div>
<div>To: <${message.headers.to}></div>

<br>

Would be good to share the common code between these files.

@elie222 elie222 merged commit 7ade62f into elie222:main Jul 9, 2024
@coderabbitai coderabbitai bot mentioned this pull request Jan 24, 2025
@coderabbitai coderabbitai bot mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: forwarding emails from Mail client doesn't include the body

3 participants

Comments