Skip to content

Commit

Permalink
added hints for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
jobisoft committed Mar 10, 2021
1 parent 5506b1c commit 4b1f7ce
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
8 changes: 8 additions & 0 deletions includes/messages/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let attachments = await browser.messages.listAttachments(messageId);
for (let att of attachments) {
let file = await browser.messages.getAttachmentFile(
message.id,
att.partName
);
let content = await file.text();
}
25 changes: 25 additions & 0 deletions messages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ Lists all of the attachments of a message.
:type: (integer)


.. api-header::
:label: Return type (`Promise`_)


.. api-member::
:type: array of :ref:`messages.Attachment`


.. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

.. api-header::
:label: Required permissions

Expand Down Expand Up @@ -257,11 +267,26 @@ Gets the content of an attachment as a DOM ``File`` object.
:type: (string)


.. api-header::
:label: Return type (`Promise`_)


.. api-member::
:type: `File <https://developer.mozilla.org/en-US/docs/Web/API/File>`_


.. _Promise: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

.. api-header::
:label: Required permissions

- :permission:`messagesRead`

The most simple way to get the content of an attachment is to use the ``text()`` method of the ``File`` object:

.. literalinclude:: includes/messages/file.js
:language: JavaScript

.. _messages.query:

query(queryInfo)
Expand Down
14 changes: 12 additions & 2 deletions overlay/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@
},
{
"name": "listAttachments",
"added": "88"
"added": "88",
"returns": {
"type": "array",
"items": {
"$ref": "Attachment"
}
}
},
{
"name": "getAttachmentFile",
"added": "88"
"added": "88",
"hints": "The most simple way to get the content of an attachment is to use the ``text()`` method of the ``File`` object:<literalinclude>includes/messages/file.js<lang>JavaScript</lang></literalinclude>",
"returns": {
"$ref": "extensionTypes.File"
}
},
{
"name": "query",
Expand Down
13 changes: 13 additions & 0 deletions update-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def get_type(obj, name):

def link_ref(ref):
global additional_type_used
if ref == "extensionTypes.File":
return "`File <https://developer.mozilla.org/en-US/docs/Web/API/File>`_"
if ref == "extensionTypes.Date":
return "`Date <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date>`_"
if ref == "runtime.Port":
Expand Down Expand Up @@ -161,6 +163,12 @@ def format_changes(obj, inline = False):
lines.extend(api_header("Changes in Thunderbird " + k, api_member(name=replace_code(v))))
return lines

def format_hints(obj):
lines = []
if "hints" in obj:
lines.extend(replace_code(obj['hints']).split("\n"))
return lines

def get_api_member_parts(name, value):
parts = {
"name" : "",
Expand Down Expand Up @@ -525,6 +533,11 @@ def format_namespace(manifest, namespace):
lines.extend(format_permissions(function, namespace))
#lines.extend(enum_lines)

if "hints" in function:
lines.extend(format_hints(function))




if "events" in namespace:
lines.append("")
Expand Down

0 comments on commit 4b1f7ce

Please sign in to comment.