Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for downloading inline images using the -SaveAttachmentsTo parameter #209

Closed
higginsta opened this issue Jul 15, 2019 · 4 comments
Assignees

Comments

@higginsta
Copy link

Is your feature request related to a problem? Please describe.

The -SaveAttachmentsTo parameter does not work for all messages that contain inline images. Some email clients like iPhone Mail do not specify inline images as being attachments.

Describe the solution you'd like

Please add the ability for the -SaveAttachmentsTo parameter to parse files that are included inline with a message (located within BodyParts instead of Attachments)

Describe alternatives you've considered
The sample code you provided as a workaround for inline images works as expected.

Additional context

You helped me work through this issue via Discord on July 10th, 2019 (using code similar to what Get-GSGmailMessage is already doing)

@scrthq
Copy link
Member

scrthq commented Jul 15, 2019

Thanks, @higginsta !! Sample code for (my own) reference that was shared on Discord:

Import-Module PSGSuite
$msg = Get-GSGmailMessage -Id $id -Verbose -ParseMessage

$downloadPath = "~\Downloads"

foreach ($att in ($msg.BodyParts | Where-Object {$_.FileName})) {
    $cleanedName = $att.FileName -replace "[$([RegEx]::Escape("$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')"))]","_" 
    $resPath = (Resolve-Path $downloadPath).Path
    $fileName = Join-Path $resPath $cleanedName
    Write-Verbose "Saving attachment to path '$fileName'"
    $stream = [System.IO.File]::Create($fileName)
    $att.ContentObject.DecodeTo($stream)
    $stream.Close()
}

@scrthq scrthq self-assigned this Jul 15, 2019
@scrthq
Copy link
Member

scrthq commented Jul 17, 2019

hey @higginsta - This is fixed and confirmed working as expected! The behavior now is that it will grab both BodyParts and Attachments that have a FileName listed for them, then sort by unique FileName + ContentId, then download the resulting list to the path specified in SaveAttachmentsTo. The unique sort is due to inline images also showing as attachments depending on the sending mail service, which would result in duplicate attachment downloads without the unique sort. ContentId and FileName match when the file is listed in both areas and I've tested with a couple sample messages that this works as expected.

@scrthq
Copy link
Member

scrthq commented Jul 17, 2019

I'll let you know as soon as available on the Gallery!

scrthq added a commit that referenced this issue Jul 17, 2019
## 2.30.0

* [Issue #193](#193)
  * Added: Drive Revision functions:
    * Get-GSDriveRevision
    * Remove-GSDriveRevision
    * Update-GSDriveRevision
* [Issue #210](#210)
  * Fixed: Update-GSUser was not accepting User ID's as the User parameter
* [Issue #209](#209)
  * Added: Support for inline image downloading with Get-GSGmailMessage where the image is not included on the Attachments property of the parsed message object.
  * Fixed: Get-GSGmailMessage will now automatically set the Format to Raw if either ParseMessage or SaveAttachmentsTo is passed, as ParseMessage is a requirement in order to be able to access the message attachments as needed.
* [Issue #204](#204)
  * Added: Recurse parameter to Get-GSDriveFileList to allow recursively listing all files and subfolders underneath the result set. Confirmed setting the Limit parameter also works as expected with Recurse included, stopping is the original limit is reached.
  * Added: Get-GSDriveFolderSize function to return the calculated total size of the files in the specified folder(s).
* Miscellaneous
  * Added: Rfc822MsgId parameter to Get-GSGmailMessageList to easily build a query looking for a specific RFS 822 Message ID.
  * Added: Pipeline support for *-GSDrivePermission functions to enable piping Drive Files into them to manage permissions without looping manually.
scrthq added a commit that referenced this issue Jul 17, 2019
## 2.30.0

* [Issue #193](#193)
  * Added: Drive Revision functions:
    * `Get-GSDriveRevision`
    * `Remove-GSDriveRevision`
    * `Update-GSDriveRevision`
* [Issue #210](#210)
  * Fixed: `Update-GSUser` was not accepting User ID's as the User parameter
* [Issue #209](#209)
  * Added: Support for inline image downloading with `Get-GSGmailMessage` where the image is not included on the Attachments property of the parsed message object.
  * Fixed: `Get-GSGmailMessage` will now automatically set the `Format` to `Raw` if either `ParseMessage` or `SaveAttachmentsTo` is passed, as `ParseMessage` is a requirement in order to be able to access the message attachments as needed.
* [Issue #204](#204)
  * Added: `Recurse` parameter to `Get-GSDriveFileList` to allow recursively listing all files and subfolders underneath the result set. Confirmed setting the `Limit` parameter also works as expected with `Recurse` included, stopping is the original limit is reached.
  * Added: `Get-GSDriveFolderSize` function to return the calculated total size of the files in the specified folder(s).
* Miscellaneous
  * Added: `Rfc822MsgId` parameter to `Get-GSGmailMessageList` to easily build a query looking for a specific RFS 822 Message ID.
  * Added: Pipeline support for `*-GSDrivePermission` functions to enable piping Drive Files into them to manage permissions without looping manually.
@scrthq
Copy link
Member

scrthq commented Jul 17, 2019

deployed!

@scrthq scrthq closed this as completed Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants