Skip to content

Commit

Permalink
Added option `showattachments [attachmentnamepattern <RegularExpressi…
Browse files Browse the repository at this point in the history
…on>]` to `gam <UserTypeEntity> print messages|threads`.
  • Loading branch information
taers232c committed May 18, 2021
1 parent 6eab88e commit e4c86c7
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 88 deletions.
118 changes: 59 additions & 59 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,65 @@ cache:
jobs:
fast_finish: true
include:
# - os: linux
# name: "Linux 64-bit Focal"
# dist: focal
# language: shell
# env:
# - DIST_UPGRADE=true
# - os: linux
# name: "Linux 64-bit Bionic"
# dist: bionic
# language: shell
# env:
# - DIST_UPGRADE=true
# - os: linux
# name: "Linux 64-bit Xenial"
# dist: xenial
# language: shell
# env:
# - DIST_UPGRADE=false
# - os: linux
# name: "Linux 64-bit Trusty"
# dist: trusty
# language: shell
# env:
# - DIST_UPGRADE=true
# - os: linux
# name: "Linux 64-bit Precise"
# dist: precise
# language: shell
# env:
# - DIST_UPGRADE=false
# - PATCHELF_VERSION=0.9
# - os: linux
# name: "Linux ARM64 Focal"
# dist: focal
# arch: arm64
# language: shell
# env:
# - DIST_UPGRADE=false
# filter_secrets: false
# - os: linux
# name: "Linux ARM64 Bionic"
# dist: bionic
# arch: arm64
# language: shell
# env:
# - DIST_UPGRADE=false
# filter_secrets: false
# - os: linux
# name: "Linux ARM64 Xenial"
# dist: xenial
# arch: arm64
# language: shell
# env:
# - DIST_UPGRADE=true
# filter_secrets: false
# - os: osx
# name: "MacOS"
# language: generic
# osx_image: xcode12.4
- os: linux
name: "Linux 64-bit Focal"
dist: focal
language: shell
env:
- DIST_UPGRADE=true
- os: linux
name: "Linux 64-bit Bionic"
dist: bionic
language: shell
env:
- DIST_UPGRADE=true
- os: linux
name: "Linux 64-bit Xenial"
dist: xenial
language: shell
env:
- DIST_UPGRADE=false
- os: linux
name: "Linux 64-bit Trusty"
dist: trusty
language: shell
env:
- DIST_UPGRADE=true
- os: linux
name: "Linux 64-bit Precise"
dist: precise
language: shell
env:
- DIST_UPGRADE=false
- PATCHELF_VERSION=0.9
- os: linux
name: "Linux ARM64 Focal"
dist: focal
arch: arm64
language: shell
env:
- DIST_UPGRADE=false
filter_secrets: false
- os: linux
name: "Linux ARM64 Bionic"
dist: bionic
arch: arm64
language: shell
env:
- DIST_UPGRADE=false
filter_secrets: false
- os: linux
name: "Linux ARM64 Xenial"
dist: xenial
arch: arm64
language: shell
env:
- DIST_UPGRADE=true
filter_secrets: false
- os: osx
name: "MacOS"
language: generic
osx_image: xcode12.4
- os: windows
name: "Windows 64-bit"
language: shell
Expand Down
1 change: 1 addition & 0 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5354,6 +5354,7 @@ gam <UserTypeEntity> print messages|threads [todrive <ToDriveAttribute>*]
[countsonly|positivecountsonly] [useronly]
[headers all|<SMTPHeaderList>]
[showlabels] [showbody] [showsize] [showsnippet]
[showattachments [attachmentnamepattern <RegularExpression>]]
[convertcrnl] [delimiter <Character>]

# Users - Gmail - Profile
Expand Down
5 changes: 4 additions & 1 deletion src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
6.03.19

Rebuild pyinstaller bootloader on Windows to avoid false positive virus detection.
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.

6.03.18

Expand Down
39 changes: 33 additions & 6 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51096,6 +51096,21 @@ def _showMessage(result, j, jcount):
Ind.Decrement()
parameters['messagesProcessed'] += 1

def _getAttachmentNames(messageId, payload, attachmentNamePattern, attachmentNames):
for part in payload.get('parts', []):
if 'attachmentId' in part['body']:
for header in part['headers']:
if header['name'] in {'Content-Type', 'Content-Disposition'}:
mg = ATTACHMENT_NAME_PATTERN.match(header['value'])
if not mg:
continue
attachmentName = mg.group(1)
if (not attachmentNamePattern) or attachmentNamePattern.match(attachmentName):
attachmentNames.append(attachmentName)
break
else:
_getAttachmentNames(messageId, part, attachmentNamePattern, attachmentNames)

def _printMessage(user, result):
if parameters['maxToProcess'] and parameters['messagesProcessed'] == parameters['maxToProcess']:
return
Expand Down Expand Up @@ -51134,6 +51149,12 @@ def _printMessage(user, result):
row['Body'] = _getMessageBody(result['payload'])
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
csvPF.WriteRowTitles(row)
parameters['messagesProcessed'] += 1

Expand Down Expand Up @@ -51277,9 +51298,9 @@ def _batchPrintShowMessagesThreads(service, user, jcount, messageIds):
show_size = True
elif myarg == 'showsnippet':
show_snippet = True
elif showMode and myarg == 'showattachments':
elif myarg == 'showattachments':
show_attachments = True
elif showMode and myarg == 'attachmentnamepattern':
elif myarg == 'attachmentnamepattern':
attachmentNamePattern = getREPattern(re.IGNORECASE)
elif showMode and myarg == 'saveattachments':
save_attachments = True
Expand Down Expand Up @@ -51426,12 +51447,15 @@ def _batchPrintShowMessagesThreads(service, user, jcount, messageIds):
# gam <UserTypeEntity> print message|messages
# (((query <QueryGmail>) (matchlabel <LabelName>) [or|and])* [quick|notquick] [max_to_print <Number>] [includespamtrash])|(ids <MessageIDEntity>)
# [labelmatchpattern <RegularExpression>]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet] [convertcrnl] [delimiter <Character>] [todrive <ToDriveAttribute>*]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet]
# [showattachments [attachmentnamepattern <RegularExpression>]]
# [convertcrnl] [delimiter <Character>] [todrive <ToDriveAttribute>*]
# [countsonly|positivecountsonly] [useronly]
# gam <UserTypeEntity> show message|messages
# (((query <QueryGmail>) (matchlabel <LabelName>) [or|and])* [quick|notquick] [max_to_show <Number>] [includespamtrash])|(ids <MessageIDEntity>)
# [labelmatchpattern <RegularExpression>]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet] [showattachments [attachmentnamepattern <RegularExpression>]]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet]
# [showattachments [attachmentnamepattern <RegularExpression>]]
# [countsonly|positivecountsonly] [useronly]
# [saveattachments [attachmentnamepattern <RegularExpression>]] [targetfolder <FilePath>] [overwrite [<Boolean>]]
def printShowMessages(users):
Expand All @@ -51440,12 +51464,15 @@ def printShowMessages(users):
# gam <UserTypeEntity> print thread|threads
# (((query <QueryGmail>) (matchlabel <LabelName>) [or|and])* [quick|notquick] [max_to_print <Number>] [includespamtrash])|(ids <ThreadIDEntity>)
# [labelmatchpattern <RegularExpression>]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet] [convertcrnl] [delimiter <Character>] [todrive <ToDriveAttribute>*]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet]
# [showattachments [attachmentnamepattern <RegularExpression>]]
# [convertcrnl] [delimiter <Character>] [todrive <ToDriveAttribute>*]
# [countsonly|positivecountsonly] [useronly]
# gam <UserTypeEntity> show thread|threads
# (((query <QueryGmail>) (matchlabel <LabelName>) [or|and])* [quick|notquick] [max_to_show <Number>] [includespamtrash])|(ids <ThreadIDEntity>)
# [labelmatchpattern <RegularExpression>]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet] [showattachments [attachmentnamepattern <RegularExpression>]]
# [headers all|<SMTPHeaderList>] [showlabels] [showbody] [showsize] [showsnippet]
# [showattachments [attachmentnamepattern <RegularExpression>]]
# [countsonly|positivecountsonly] [useronly]
# [saveattachments [attachmentnamepattern <RegularExpression>]] [targetfolder <FilePath>] [overwrite [<Boolean>]]
def printShowThreads(users):
Expand Down
33 changes: 16 additions & 17 deletions src/travis/windows-before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,25 @@ cd $mypath
$pip install --upgrade pip
$pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 $pip install -U
$pip install --upgrade -r src/requirements.txt
#$pip install --upgrade pyinstaller
$pip install --upgrade pyinstaller
# Install PyInstaller from source and build bootloader
# to try and avoid getting flagged as malware since
# lots of malware uses PyInstaller default bootloader
# https://stackoverflow.com/questions/53584395/how-to-recompile-the-bootloader-of-pyinstaller
echo "Downloading PyInstaller..."
wget --quiet https://github.com/pyinstaller/pyinstaller/archive/$PYINSTALLER_COMMIT.tar.gz
tar xf $PYINSTALLER_COMMIT.tar.gz
mv pyinstaller-$PYINSTALLER_COMMIT pyinstaller
cd pyinstaller/bootloader
echo "bootloader before:"
md5sum ../PyInstaller/bootloader/Windows-${BITS}bit/*

$python ./waf all --target-arch=${BITS}bit --msvc_version "msvc 14.0"

echo "bootloader after:"
md5sum ../PyInstaller/bootloader/Windows-${BITS}bit/*
echo "PATH: $PATH"
cd ..
$python setup.py install
#echo "Downloading PyInstaller..."
#wget --quiet https://github.com/pyinstaller/pyinstaller/archive/$PYINSTALLER_COMMIT.tar.gz
#tar xf $PYINSTALLER_COMMIT.tar.gz
#mv pyinstaller-$PYINSTALLER_COMMIT pyinstaller
#cd pyinstaller/bootloader
#echo "bootloader before:"
#md5sum ../PyInstaller/bootloader/Windows-${BITS}bit/*
#
#$python ./waf all --target-arch=${BITS}bit --msvc_version "msvc 14.0"
#
#echo "bootloader after:"
#md5sum ../PyInstaller/bootloader/Windows-${BITS}bit/*
#echo "PATH: $PATH"
#cd ..
#$python setup.py install
echo "cd to $mypath"
cd $mypath
ls -l pyinstaller
6 changes: 1 addition & 5 deletions src/travis/windows-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ export gampath="dist/gamadv-xtd3"
rm -rf $gampath
mkdir -p $gampath
export gampath=$(readlink -e $gampath)
export python=/c/python/python.exe
echo "Python Version"
$python -V
echo "Compile: $python -OO -v -c pyinstaller/pyinstaller.py --clean --noupx -F --distpath $gampath gam.spec"
$python -OO -v -c pyinstaller/pyinstaller.py --clean --noupx -F --distpath $gampath gam.spec
pyinstaller --clean --noupx -F --distpath $gampath gam.spec
export gam="${gampath}/gam"
echo "running compiled GAM..."
$gam version
Expand Down

0 comments on commit e4c86c7

Please sign in to comment.