dreamhunter2333 / cloudflare_temp_email

CloudFlare free temp domain email 免费收发 临时域名邮箱 支持附件 IMAP SMTP TelegramBot
https://mail.awsl.uk
MIT License
2.15k stars 801 forks source link

feat: add mail id and url in webhook #443

Closed dreamhunter2333 closed 3 weeks ago

dreamhunter2333 commented 3 weeks ago

User description

429


PR Type

Enhancement, Documentation


Description


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[bot] commented 3 weeks ago

    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.
    github-actions[bot] commented 3 weeks ago

    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]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/443/files#diff-9816bb6131d16919d3ca2c71fb0911d2cb73cc9a49d75394c6206ff15f1aa4d8R94-R94) ```diff -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]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/443/files#diff-a8888cea638671df084f06f14c82a84294903585f3a218161847b0a96d044821R29-R29) ```diff -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]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/443/files#diff-fcc08fd5aa3c190d0d45c7e3dd208e5ee831d360b272fdd5869607cf472c5eb1R393-R398) ```diff 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]](https://github.com/dreamhunter2333/cloudflare_temp_email/pull/443/files#diff-9816bb6131d16919d3ca2c71fb0911d2cb73cc9a49d75394c6206ff15f1aa4d8R112-R112) ```diff -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