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

attachment in send-email is causing an error "argument list too long" in docker #459

Open
brotherko opened this issue Apr 12, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@brotherko
Copy link

brotherko commented Apr 12, 2024

There is a limit in linux that only allow certain amount of bytes in the argument of a single command
I'm not sure if this is an issue with my specific my environment but a 200KB attachment could break this limit

To reproduce

  1. mgc login
  2. generate a file that is ~ 200kb
  3. update the command in contentBytes then run it
mgc users send-mail post \
--body '{
"message": {
"subject": "hi",
"body": {
  "contentType": "text",
  "content": "test"
},
"toRecipients": [
  {
    "emailAddress": {
      "address": "abc@abc.com"
    }
  }
],
"attachments": [
  {
    "@odata.type": "#microsoft.graph.fileAttachment",
    "name": "screenshot.png",
    "contentBytes": "'"$(cat ./file.png | base64)"'",
    "contentId": "screenshot"
  }]
},
"saveToSentItems": "false"
}'

Fix
Allow user to supply the their --body payload in a separate file like what CURL did? see @filename in the below doc
https://everything.curl.dev/http/post/simple.html

@calebkiage
Copy link
Collaborator

calebkiage commented Apr 12, 2024

Hello @brotherko, thanks for reporting this issue. The CLI supports using response files to get around argument limits in shells. You can create a text file (e.g. args.rsp), enter each arg separated by spaces, then use mgc users send-mail post @args.rsp.

The syntax rules for response files are defined in the page linked above.

Let me know if this information helps with your issue.

@brotherko
Copy link
Author

brotherko commented Apr 15, 2024

Hi @calebkiage Thanks! I'm wondering if this is a well known pattern for a .NET application to support syntax like this by default? I think it might be helpful to put it in the README for anyone who didn't work on a .NET application before(like myself)

However, still, I had a hard time crafting a JSON string that works.

  1. Double quote is automatically removed during execution even when I escape it with back slash
  2. Space is treated as a new token

This is what I've tried (I know it's not a valid request for the send-mail api. I just want to see if it parses the string properly)

--user-id
1234567
--body
"{\"name\":\"test\"\}"

This is what I got:
Unrecognized command or argument 'name\:\test\\}'.

@calebkiage
Copy link
Collaborator

Hello @brotherko, this is a limitation of the commandline parser we use currently. It doesn't support escaping quotes very well. See dotnet/command-line-api#1755 and dotnet/command-line-api#1758

We might need to customize the response file parsing logic like the .NET team did for the dotnet cli (dotnet/runtime#76271)

@calebkiage calebkiage added enhancement New feature or request and removed Needs: Attention 👋 labels Apr 15, 2024
@brotherko
Copy link
Author

Understood so I assume there is no work around for this issue? Would it be on the road map anytime soon?

@calebkiage
Copy link
Collaborator

Hi @brotherko, for now there's no workaround without a code change. Would you be willing to contribute code for this? We accept community contributions, and it would be the fastest way to get this change out. I'm happy to guide you through the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants