-
Notifications
You must be signed in to change notification settings - Fork 67
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
SaveAttachmentsTo will fail if the name contains invalid path characters (Windows) #169
Comments
@craigminihan - Thanks for opening this up! My initial thought to resolve this is replace any unsafe characters with underscores; would this be an alright approach? If not, what would the preferred behavior be? I should be able to get this resolved pretty quickly tonight and will proceed with underscores as the replacement character unless otherwise noted 🙂 |
…support ## 2.26.0 * [Issue #169](#169) * Fixed: `Get-GSGmailMessage` fails to download attachments containing invalid characters (e.g. `:`) * [Issue #168](#168) * Added: `Add-GSUserLocation` * Updated: `New-GSUser` and `Update-GSUser` to add in Location support * Miscellaneous * Improved pipeline support for the `User` parameter across all pertinent functions, i.e. Drive, Calendar, Gmail, Sheets & Tasks APIs.
@craigminihan - Fix is being rolled out with v2.26.0, should be on the Gallery shortly! Here's what I've added, for reference: foreach ($att in $attachments) {
$cleanedName = $att.FileName -replace "[$(([System.IO.Path]::GetInvalidFileNameChars() + [System.IO.Path]::GetInvalidPathChars()) -join '')]","_" # <<<<< FileName cleanup via RegEx replace
$fileName = Join-Path $resPath $cleanedName
Write-Verbose "Saving attachment to path '$fileName'"
$stream = [System.IO.File]::Create($fileName)
$att.ContentObject.DecodeTo($stream)
$stream.Close()
} |
nice - thanks for resolving this so quickly! |
Describe the bug
Passing
SaveAttachmentsTo
toGet-GSGmailMessage
fails when the attachment file name contains characters treated as invalid by Windows.An exception is thrown in the call to
[System.IO.File]::Create($fileName)
.To Reproduce
Steps to reproduce the behavior:
ENDEP1_2019-03-29 08:30:00.docx
Get-GSGmailMessage -SaveAttachmentsTo
Expected behavior
The file should appear in the folder with invalid characters substituted out.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: