Skip to content

Commit

Permalink
Display attachment name and MIME type in print messages
Browse files Browse the repository at this point in the history
  • Loading branch information
taers232c committed May 18, 2021
1 parent e4c86c7 commit d7cf5c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Added option `showattachments [attachmentnamepattern <RegularExpression>]` to
`gam <UserTypeEntity> 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

Expand Down
17 changes: 9 additions & 8 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand All @@ -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']:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d7cf5c7

Please sign in to comment.