Thunderbird - 如何确定清单 v3 消息的附件?

问题描述 投票:0回答:1

我使用了这个稳定文档的示例

let attachments = await browser.messages.listAttachments(messageId);
for (let att of attachments) {
    let file = await browser.messages.getAttachmentFile(
        messageId,
        att.partName
    );
    let content = await file.text();
}

不起作用。

https://webextension-api.thunderbird.net/en/stable/messages.html

我的扩展的background.js中的其他源代码

async function mail_display(tab, message) {
  console.log(`Message displayed in tab ${message.messageId}: ${message.subject}`);
  console.log(message.id); 
  try {
 

    let attachments = await browser.messages.listAttachments(message.id);
    console.log(attachments);
    for (let att of attachments) {
      let file = await browser.messages.getAttachmentFile(messageId, att.partName);
      console.log(file);
      let content = await file.text();
    }
  } catch(error) {
    console.log(`Fehler beim Abrufen der Attachments: ${error}`);
  }
}

browser.messageDisplay.onMessageDisplayed.addListener(mail_display);

它返回一个没有附件的空数组

thunderbird
1个回答
0
投票

好吧,我找到了一个有效的解决方案:

// background.js in Thunderbird extension
async function mail_display(tab, message) {
  // Log message: "Message displayed in tab {message.id}: {message.subject}"
  console.log(`Message displayed in tab ${message.id}: ${message.subject}`);

  // Try to load the full message
  try {
    // Save the full message in the message_full variable
    message_full = await browser.messages.getFull(message.id);

    // Log the message (optional)
    //console.log(message);

    // Call the listAttachments() method to get the list of attachments
    let attachments = await browser.messages.listAttachments(message.id);

    // Log the attachments
    console.log(attachments);

    // Iterate over the attachments
    for (let att of attachments) {
      // Call the getAttachmentFile() method to get the file for the attachment
      let file = await browser.messages.getAttachmentFile(message.id, att.partName);

      // Call the text() method to get the attachment content as text
      let content = await file.text();

      // Log the attachment content
      console.log(content);
    }
  } catch (error) {
    // Log the error message
    console.log(`Error with loading the Attachments: ${error}`);
  }
}

browser.messageDisplay.onMessageDisplayed.addListener(mail_display);

注:

  1. 如果电子邮件是 openPGP 加密的,它似乎不起作用(!)
  2. 重新启动雷鸟
© www.soinside.com 2019 - 2024. All rights reserved.