(accessToken: string, messageId: string, logger: Logger)
| 575 | } |
| 576 | |
| 577 | async function markEmailAsRead(accessToken: string, messageId: string, logger: Logger) { |
| 578 | const modifyUrl = `https://gmail.googleapis.com/gmail/v1/users/me/messages/${messageId}/modify` |
| 579 | |
| 580 | try { |
| 581 | const response = await fetch(modifyUrl, { |
| 582 | method: 'POST', |
| 583 | headers: { |
| 584 | Authorization: `Bearer ${accessToken}`, |
| 585 | 'Content-Type': 'application/json', |
| 586 | }, |
| 587 | body: JSON.stringify({ removeLabelIds: ['UNREAD'] }), |
| 588 | }) |
| 589 | |
| 590 | if (!response.ok) { |
| 591 | await response.body?.cancel().catch(() => {}) |
| 592 | throw new Error( |
| 593 | `Failed to mark email ${messageId} as read: ${response.status} ${response.statusText}` |
| 594 | ) |
| 595 | } |
| 596 | } catch (error) { |
| 597 | logger.error(`Error marking email ${messageId} as read:`, error) |
| 598 | throw error |
| 599 | } |
| 600 | } |
no test coverage detected