diff --git a/src/GamUpdate.txt b/src/GamUpdate.txt index 0f66aa9b..8da9f071 100644 --- a/src/GamUpdate.txt +++ b/src/GamUpdate.txt @@ -2,8 +2,8 @@ Added option `showattachments [attachmentnamepattern ]` to `gam print messages|threads`. This adds the column `Attachments` -that shows the number of attachments and columns `Attachments.n` that show the -attachment names. +that shows the number of attachments and columns `Attachments.n.name` and `Attachments.n.mimeType` +that show the attachment names and MIME types. 6.03.18 diff --git a/src/gam/__init__.py b/src/gam/__init__.py index c8a84aea..10721dde 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -51096,7 +51096,7 @@ def _showMessage(result, j, jcount): Ind.Decrement() parameters['messagesProcessed'] += 1 - def _getAttachmentNames(messageId, payload, attachmentNamePattern, attachmentNames): + def _getAttachments(messageId, payload, attachmentNamePattern, attachments): for part in payload.get('parts', []): if 'attachmentId' in part['body']: for header in part['headers']: @@ -51106,10 +51106,10 @@ def _getAttachmentNames(messageId, payload, attachmentNamePattern, attachmentNam continue attachmentName = mg.group(1) if (not attachmentNamePattern) or attachmentNamePattern.match(attachmentName): - attachmentNames.append(attachmentName) + attachments.append((attachmentName, part['mimeType'])) break else: - _getAttachmentNames(messageId, part, attachmentNamePattern, attachmentNames) + _getAttachments(messageId, part, attachmentNamePattern, attachments) def _printMessage(user, result): if parameters['maxToProcess'] and parameters['messagesProcessed'] == parameters['maxToProcess']: @@ -51150,11 +51150,12 @@ def _printMessage(user, result): else: row['Body'] = escapeCRsNLs(_getMessageBody(result['payload'])) if show_attachments: - attachmentNames = [] - _getAttachmentNames(result['id'], result['payload'], attachmentNamePattern, attachmentNames) - row['Attachments'] = len(attachmentNames) - for i, attachmentName in enumerate(attachmentNames): - row[f'Attachments.{i}'] = attachmentName + attachments = [] + _getAttachments(result['id'], result['payload'], attachmentNamePattern, attachments) + row['Attachments'] = len(attachments) + for i, attachment in enumerate(attachments): + row[f'Attachments.{i}.name'] = attachment[0] + row[f'Attachments.{i}.mimeType'] = attachment[1] csvPF.WriteRowTitles(row) parameters['messagesProcessed'] += 1