Skip to content

Commit f18962a

Browse files
Merge pull request #10 from loadsmart/filterAttachmentsWithoutId
Filter attachments without ID
2 parents 2b8dd40 + a705f27 commit f18962a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

gmail_wrapper/entities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def attachments(self):
112112
return [
113113
Attachment(self.id, self._client, part)
114114
for part in (parts if parts else [])
115-
if part["filename"]
115+
if part["filename"] and part["body"] and part["body"].get("attachmentId")
116116
]
117117

118118
def modify(self, add_labels=None, remove_labels=None):

tests/test_entities.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ def test_it_generates_attachment_objects(self, client, raw_complete_message):
6565
]
6666
)
6767

68+
def test_it_does_not_generate_attachment_objects_for_attachments_without_id(
69+
self, client, raw_complete_message
70+
):
71+
complete_message = Message(client, raw_complete_message)
72+
raw_complete_message["payload"]["parts"].append(
73+
{
74+
"body": {"size": 0, "data": ""},
75+
"filename": "invalid.pdf",
76+
"partId": "BB710",
77+
"mimeType": "application/pdf",
78+
}
79+
)
80+
assert len(complete_message.attachments) == 1
81+
assert complete_message.attachments[0].id
82+
assert complete_message.attachments[0].filename != "invalid.pdf"
83+
6884
def test_it_returns_empty_list_if_no_attachments(
6985
self, client, raw_complete_message
7086
):

0 commit comments

Comments
 (0)