add tag
Anonymous 1399
I have this python code block set for an app that displays email on the FE from json.

```
for list_values in received_mails_folder:
    user_content = {}
    data = conn.get_object(Bucket=bucket, Key=list_values)
    read_content = data['Body'].read()
    mail = mailparser.parse_from_bytes(read_content)
    receiver_name,receiver_mail = [x for x in mail.to][0]
    sender_name,sender_mail =  [x for x in mail.from_][0]
    subject = mail.subject
    content = list(mail.text_plain)
    body = mail.body
    attach = mail.attachments
    for item in attach:
        attach_name = item["filename"]
        attach_path = uploads_dir + "/" + attach_name
        print(attach_path)
        user_content['ATTACH'] = attach_path
    date = mail.date
    user_content['TO'] = receiver_mail
    user_content['FROM'] = sender_mail
    user_content['SUBJECT'] = subject
    user_content['MESSAGE'] = content
    user_content['NAME'] = sender_name
    user_content['DATE'] = str(date)

    final_list.append(user_content)
  
return final_list
```

So if the there are multiple attachments from the same FROM email, how do i get them together? Currently, only the last attachment in a mail with multiple attachments is entered into the json response.
Top Answer
Jack Douglas
Rather than overwriting `user_content['ATTACH']` you could append to a sub-list. So instead of:

```
for item in attach:
    attach_name = item["filename"]
    attach_path = uploads_dir + "/" + attach_name
    print(attach_path)
    user_content['ATTACH'] = attach_path
```

use something like:

```
user_content['ATTACH'] = []
for item in attach:
    attach_name = item["filename"]
    attach_path = uploads_dir + "/" + attach_name
    print(attach_path)
    user_content['ATTACH'].append(attach_path)
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.