Closed higginsta closed 5 years ago
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()
}
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.
I'll let you know as soon as available on the Gallery!
deployed!
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 withinBodyParts
instead ofAttachments
)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)