Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mail id and url in webhook #443

Merged
merged 1 commit into from
Sep 9, 2024
Merged

feat: add mail id and url in webhook #443

merged 1 commit into from
Sep 9, 2024

Conversation

dreamhunter2333
Copy link
Owner

@dreamhunter2333 dreamhunter2333 commented Sep 9, 2024

User description

#429


PR Type

Enhancement, Documentation


Description

  • Added functionality to query mails by ID in the mailbox view.
  • Enhanced webhook payload to include mail ID and URL.
  • Added new API endpoint to fetch mail by ID.
  • Updated documentation to include FRONTEND_URL configuration.
  • Modified SQL queries to fetch mail ID along with raw email.

Changes walkthrough 📝

Relevant files
Enhancement
8 files
Index.vue
Add mail ID query functionality in the mailbox view           

frontend/src/views/Index.vue

  • Added useRoute to handle route changes.
  • Introduced mailIdQuery and showMailIdQuery for querying mails by ID.
  • Added a new input field and button for querying mails by ID.
  • Updated fetchMailData to handle mail ID queries.
  • +45/-4   
    mail_webhook_settings.ts
    Include mail ID and URL in webhook payload                             

    worker/src/admin_api/mail_webhook_settings.ts

  • Included mail ID and URL in the webhook payload.
  • Modified SQL query to fetch mail ID along with raw email.
  • +5/-3     
    common.ts
    Enhance webhook payload with mail ID and URL                         

    worker/src/common.ts

  • Added logging for webhook sending.
  • Included mail ID and URL in the webhook payload.
  • Modified triggerWebhook to fetch mail ID based on address and message
    ID.
  • +9/-1     
    index.ts
    Pass message ID to `triggerWebhook` function                         

    worker/src/email/index.ts

    • Updated triggerWebhook call to include message_id.
    +1/-1     
    index.ts
    Add API endpoint to fetch mail by ID                                         

    worker/src/mails_api/index.ts

    • Added new API endpoint to fetch mail by ID.
    +9/-0     
    webhook_settings.ts
    Enhance webhook settings with mail ID and URL                       

    worker/src/mails_api/webhook_settings.ts

  • Included mail ID and URL in the webhook payload.
  • Modified SQL query to fetch mail ID along with raw email.
  • +5/-3     
    index.ts
    Extend `WebhookMail` type with ID and URL                               

    worker/src/models/index.ts

  • Added id and url fields to WebhookMail type.
  • Updated WebhookSettings body template to include id and url.
  • +4/-0     
    types.d.ts
    Add `FRONTEND_URL` to environment bindings                             

    worker/src/types.d.ts

    • Added FRONTEND_URL to Bindings type.
    +3/-0     
    Documentation
    2 files
    cli.md
    Document `FRONTEND_URL` configuration in CLI docs               

    vitepress-docs/docs/en/cli.md

    • Documented FRONTEND_URL configuration.
    +2/-0     
    worker.md
    Document `FRONTEND_URL` configuration in CLI docs (Chinese)

    vitepress-docs/docs/zh/guide/cli/worker.md

    • Documented FRONTEND_URL configuration in Chinese.
    +2/-0     
    Configuration changes
    1 files
    wrangler.toml.template
    Add `FRONTEND_URL` to wrangler template                                   

    worker/wrangler.toml.template

    • Added FRONTEND_URL configuration.
    +2/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3 labels Sep 9, 2024
    Copy link

    github-actions bot commented Sep 9, 2024

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🔒 No security concerns identified
    ⚡ Key issues to review

    Possible Bug
    The mailIdQuery is checked if it is greater than 0, but it is initialized as an empty string. This could lead to unexpected behavior. Consider initializing mailIdQuery as a number or adjusting the condition.

    Logging
    The console.log statement for webhook sending should be removed or replaced with a proper logging mechanism before deploying to production.

    Copy link

    github-actions bot commented Sep 9, 2024

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Parse mailIdQuery as an integer to ensure correct comparison

    The mailIdQuery should be parsed as an integer to ensure it is compared correctly in
    the condition if (mailIdQuery.value > 0).

    frontend/src/views/Index.vue [94]

    -const mailIdQuery = ref("")
    +const mailIdQuery = ref(0)
     
    Suggestion importance[1-10]: 7

    Why:

    7
    Ensure raw is defined before calling commonParseMail

    Add a check to ensure raw is not undefined before calling commonParseMail to prevent
    potential runtime errors.

    worker/src/admin_api/mail_webhook_settings.ts [29]

    -const parsedEmail = await commonParseMail(raw);
    +const parsedEmail = raw ? await commonParseMail(raw) : null;
     
    Suggestion importance[1-10]: 7

    Why:

    7
    Ensure mailId is defined before constructing the webhookMail object

    Add a check to ensure mailId is not undefined before constructing the webhookMail
    object to prevent potential runtime errors.

    worker/src/common.ts [393-398]

     const webhookMail = {
         id: mailId || "",
    -    url: c.env.FRONTEND_URL ? `${c.env.FRONTEND_URL}?mail_id=${mailId}` : "",
    +    url: mailId && c.env.FRONTEND_URL ? `${c.env.FRONTEND_URL}?mail_id=${mailId}` : "",
         from: parsedEmail?.sender || "",
         to: address,
         subject: parsedEmail?.subject || "",
         raw: raw_mail,
     };
     
    Suggestion importance[1-10]: 7

    Why:

    7
    Possible issue
    Validate route.query.mail_id to ensure it is a number before assigning it to mailIdQuery.value

    Add a check to ensure route.query.mail_id is a valid number before assigning it to
    mailIdQuery.value to prevent potential errors.

    frontend/src/views/Index.vue [112]

    -mailIdQuery.value = route.query.mail_id;
    +mailIdQuery.value = isNaN(Number(route.query.mail_id)) ? 0 : Number(route.query.mail_id);
     
    Suggestion importance[1-10]: 7

    Why:

    7

    @dreamhunter2333 dreamhunter2333 merged commit 393c590 into main Sep 9, 2024
    1 check passed
    @dreamhunter2333 dreamhunter2333 deleted the feature/dev branch September 9, 2024 14:29
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    documentation Improvements or additions to documentation enhancement New feature or request Review effort [1-5]: 3
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant