[GH-ISSUE #88] Message delete using curl on windows #60

Closed
opened 2026-03-15 12:19:28 +03:00 by kerem · 13 comments
Owner

Originally created by @gitgrub on GitHub (Apr 11, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/88

Hello,

I have a problem deleting a single message using curl.
Using the "try" button in the api doc works.
But using the curl method deletes all messages. My curl command is:
curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json" -d '{"ids":["505597d0-1367-456b-8690-b957dde261bb"]}'

Actually using python with your api, but trying to delete a message deleted all of them. So I thought I am doing something wrong, that's why I used curl for a test.

What am I doing wrong?

Originally created by @gitgrub on GitHub (Apr 11, 2023). Original GitHub issue: https://github.com/axllent/mailpit/issues/88 Hello, I have a problem deleting a single message using curl. Using the "try" button in the api doc works. But using the curl method deletes all messages. My curl command is: ` curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json" -d '{"ids":["505597d0-1367-456b-8690-b957dde261bb"]}' ` Actually using python with your api, but trying to delete a message deleted all of them. So I thought I am doing something wrong, that's why I used curl for a test. What am I doing wrong?
kerem 2026-03-15 12:19:28 +03:00
  • closed this issue
  • added the
    stale
    label
Author
Owner

@axllent commented on GitHub (Apr 11, 2023):

That is strange. I have just tested with curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json" -d '{"ids":["fb368984-a7bb-41d8-9971-222f8dda46b8"]}' and it works exactly as expected, and only message fb368984-a7bb-41d8-9971-222f8dda46b8 was deleted.

Are you 100% sure the messages weren't already deleted before you tried the curl command? The only time all messages will be deleted is if a blank array of ids (or no ids at all) are defined as valid JSON in your data. If an ID is set but doesn't exist, then nothing is deleted (eg: {"ids":["thisdoesntexist"]}).

<!-- gh-comment-id:1502766378 --> @axllent commented on GitHub (Apr 11, 2023): That is strange. I have just tested with `curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json" -d '{"ids":["fb368984-a7bb-41d8-9971-222f8dda46b8"]}'` and it works exactly as expected, and only message `fb368984-a7bb-41d8-9971-222f8dda46b8` was deleted. Are you 100% sure the messages weren't already deleted before you tried the curl command? The only time all messages will be deleted is if a blank array of `ids` (or no ids at all) are defined as valid JSON in your data. If an ID is set but doesn't exist, then nothing is deleted (eg: `{"ids":["thisdoesntexist"]}`).
Author
Owner

@gitgrub commented on GitHub (Apr 11, 2023):

Yes, tried again right now. Mailpit version is 1.5.4, OS is win10, curl version "curl 7.83.1 (Windows) libcurl/7.83.1 Schannel".
I am creating three test messages with the built in sendmail command, searching with python shows three different ids.

So I thought maybe this curl version does not send the data right. Now I tried using the command without data:
curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json"
The log says DEBU[2023/04/11 21:26:26] [db] deleted 3 messages in 129.9897ms, all messages were deleted.

Edit:
updated curl to curl 8.0.1 (x86_64-w64-mingw32), same behavior.

<!-- gh-comment-id:1503984933 --> @gitgrub commented on GitHub (Apr 11, 2023): Yes, tried again right now. Mailpit version is 1.5.4, OS is win10, curl version "curl 7.83.1 (Windows) libcurl/7.83.1 Schannel". I am creating three test messages with the built in sendmail command, searching with python shows three different ids. So I thought maybe this curl version does not send the data right. Now I tried using the command without data: ` curl -X DELETE "http://127.0.0.1:8025/api/v1/messages" -H "content-type: application/json" ` The log says `DEBU[2023/04/11 21:26:26] [db] deleted 3 messages in 129.9897ms`, all messages were deleted. Edit: updated curl to `curl 8.0.1 (x86_64-w64-mingw32)`, same behavior.
Author
Owner

@axllent commented on GitHub (Apr 12, 2023):

That is so strange. Can you please try the following for me, and post the response (leaving out your "origin" ip address):

curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d '{"ids":["1234-5678-0000"]}'

which should return something like:

{
  "args": {}, 
  "data": "{\"ids\":[\"1234-5678-0000\"]}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "26", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.81.0", 
    "X-Amzn-Trace-Id": "Root=1-64362972-1eec1de5411d2cd75aecc5dc"
  }, 
  "json": {
    "ids": [
      "1234-5678-0000"
    ]
  }, 
  "method": "DELETE", 
  "origin": ".....", 
  "url": "https://httpbin.org/anything/test"
}
<!-- gh-comment-id:1504546327 --> @axllent commented on GitHub (Apr 12, 2023): That is so strange. Can you please try the following for me, and post the response (leaving out your "origin" ip address): ``` curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d '{"ids":["1234-5678-0000"]}' ``` which should return something like: ```json { "args": {}, "data": "{\"ids\":[\"1234-5678-0000\"]}", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Content-Length": "26", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "curl/7.81.0", "X-Amzn-Trace-Id": "Root=1-64362972-1eec1de5411d2cd75aecc5dc" }, "json": { "ids": [ "1234-5678-0000" ] }, "method": "DELETE", "origin": ".....", "url": "https://httpbin.org/anything/test" } ```
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

Result is:

{
  "args": {}, 
  "data": "'{ids:[1234-5678-0000]}'", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "24", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-64362a8a-397e67a9458880ec3b1674cd"
  }, 
  "json": null, 
  "method": "DELETE", 
  "origin": "out", 
  "url": "https://httpbin.org/anything/test"
}
<!-- gh-comment-id:1504554139 --> @gitgrub commented on GitHub (Apr 12, 2023): Result is: ``` { "args": {}, "data": "'{ids:[1234-5678-0000]}'", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Content-Length": "24", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "curl/8.0.1", "X-Amzn-Trace-Id": "Root=1-64362a8a-397e67a9458880ec3b1674cd" }, "json": null, "method": "DELETE", "origin": "out", "url": "https://httpbin.org/anything/test" } ```
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

Funny, did the same from a linux laptop, now json is here:

$ curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d '{"ids":["1234-5678-0000"]}'
{
  "args": {}, 
  "data": "{\"ids\":[\"1234-5678-0000\"]}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "26", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.74.0", 
    "X-Amzn-Trace-Id": "Root=1-64362cfd-0cfd62e91ae46aff36c23958"
  }, 
  "json": {
    "ids": [
      "1234-5678-0000"
    ]
  }, 
  "method": "DELETE", 
  "origin": "out", 
  "url": "https://httpbin.org/anything/test"
}
<!-- gh-comment-id:1504562674 --> @gitgrub commented on GitHub (Apr 12, 2023): Funny, did the same from a linux laptop, now json is here: ``` $ curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d '{"ids":["1234-5678-0000"]}' { "args": {}, "data": "{\"ids\":[\"1234-5678-0000\"]}", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Content-Length": "26", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "curl/7.74.0", "X-Amzn-Trace-Id": "Root=1-64362cfd-0cfd62e91ae46aff36c23958" }, "json": { "ids": [ "1234-5678-0000" ] }, "method": "DELETE", "origin": "out", "url": "https://httpbin.org/anything/test" } ```
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

Oh hell, happy win shell quoting, on win we need:

D:\winprog\mailpit\curl>curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d "{\"ids\":[\"1234-5678-0000\"]}" 
{
  "args": {}, 
  "data": "{\"ids\":[\"1234-5678-0000\"]}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "26", 
    "Content-Type": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.0.1", 
    "X-Amzn-Trace-Id": "Root=1-643631cd-0ba95f3e598d78ad6d86ea8f"
  }, 
  "json": {
    "ids": [
      "1234-5678-0000"
    ]
  }, 
  "method": "DELETE", 
  "origin": "out", 
  "url": "https://httpbin.org/anything/test"
}
<!-- gh-comment-id:1504583440 --> @gitgrub commented on GitHub (Apr 12, 2023): Oh hell, happy win shell quoting, on win we need: ``` D:\winprog\mailpit\curl>curl -X DELETE "https://httpbin.org/anything/test" -H "content-type: application/json" -d "{\"ids\":[\"1234-5678-0000\"]}" { "args": {}, "data": "{\"ids\":[\"1234-5678-0000\"]}", "files": {}, "form": {}, "headers": { "Accept": "*/*", "Content-Length": "26", "Content-Type": "application/json", "Host": "httpbin.org", "User-Agent": "curl/8.0.1", "X-Amzn-Trace-Id": "Root=1-643631cd-0ba95f3e598d78ad6d86ea8f" }, "json": { "ids": [ "1234-5678-0000" ] }, "method": "DELETE", "origin": "out", "url": "https://httpbin.org/anything/test" } ```
Author
Owner

@axllent commented on GitHub (Apr 12, 2023):

That is interesting indeed, bloody Windows. It looks like you have uncovered the issue, although I do not know what to do about it in the docs unfortunately. The Swagger documentation is generated on-the-fly in the browser using RapidDoc which doesn't appear to have an option for that. You could potentially open a bug report there?

<!-- gh-comment-id:1504618908 --> @axllent commented on GitHub (Apr 12, 2023): That is interesting indeed, bloody Windows. It looks like you have uncovered the issue, although I do not know what to do about it in the docs unfortunately. The Swagger documentation is generated on-the-fly in the browser using [RapidDoc](https://github.com/rapi-doc/RapiDoc) which doesn't appear to have an option for that. You could potentially open a bug report there?
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

Done: https://github.com/rapi-doc/RapiDoc/issues/918
My real issue was access via python, there is a lot of discussion on stackoverflow that a body with delete command is not well defined, some servers seem to turn it into a post request, others like google just reject it. Idk, did not test this.

The hint for python users for the requests.delete command, is not to use the data parameter (which will be empty, killing all messages), but the json parameter. Now we can delete a single message.

In general: maybe it would be good not to delete all messages if the ids array is empty or not defined.
I do not know how apis like that work, but would imagine something like ids:[all] or [*].

<!-- gh-comment-id:1504682818 --> @gitgrub commented on GitHub (Apr 12, 2023): Done: https://github.com/rapi-doc/RapiDoc/issues/918 My real issue was access via python, there is a lot of discussion on stackoverflow that a body with delete command is not well defined, some servers seem to turn it into a post request, others like google just reject it. Idk, did not test this. The hint for python users for the requests.delete command, is not to use the data parameter (which will be empty, killing all messages), but the json parameter. Now we can delete a single message. In general: maybe it would be good not to delete all messages if the ids array is empty or not defined. I do not know how apis like that work, but would imagine something like ids:[all] or [*].
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

PS: in that context, so no extra issue:
The web UI is not updated after a delete operation via api.
Maybe use a timeout to not fire too many page refreshes on mass deletion?

<!-- gh-comment-id:1504705049 --> @gitgrub commented on GitHub (Apr 12, 2023): PS: in that context, so no extra issue: The web UI is not updated after a delete operation via api. Maybe use a timeout to not fire too many page refreshes on mass deletion?
Author
Owner

@axllent commented on GitHub (Apr 12, 2023):

Thanks. I'm following that thread, and if they implement a work-around I will implement it. In the meantime the "issue" lies there (and Windows) and there is nothing further I can do here unfortunately.

PS: in that context, so no extra issue: The web UI is not updated after a delete operation via api. Maybe use a timeout to not fire too many page refreshes on mass deletion?

I hear you, but this is a separate issue, and to be honest it's not something on my TODO list right now. If I am going to notify on deletions, then why not changed read statuses, tags etc... it quickly blows out into a full-featured webmail client with everything but actual emailing :-) The point is that creating a multi-browser synced mailbox (for all actions) adds a huge development overhead, and isn't an easy thing to do (correctly) - all for very little benefit. Sure, it would be great if the UI updated if a separate API request deletes or modifies something, but that's really just a nice-to-have for a small subset of users I feel.

<!-- gh-comment-id:1504787233 --> @axllent commented on GitHub (Apr 12, 2023): Thanks. I'm following that thread, and if they implement a work-around I will implement it. In the meantime the "issue" lies there (and Windows) and there is nothing further I can do here unfortunately. > PS: in that context, so no extra issue: The web UI is not updated after a delete operation via api. Maybe use a timeout to not fire too many page refreshes on mass deletion? I hear you, but this is a separate issue, and to be honest it's not something on my TODO list right now. If I am going to notify on deletions, then why not changed read statuses, tags etc... it quickly blows out into a full-featured webmail client with everything but actual emailing :-) The point is that creating a multi-browser synced mailbox (for all actions) adds a huge development overhead, and isn't an easy thing to do (correctly) - all for very little benefit. Sure, it would be great if the UI updated if a separate API request deletes or modifies something, but that's really just a nice-to-have for a small subset of users I feel.
Author
Owner

@gitgrub commented on GitHub (Apr 12, 2023):

Yes that's right, lets forget about the update thing.

<!-- gh-comment-id:1504808740 --> @gitgrub commented on GitHub (Apr 12, 2023): Yes that's right, lets forget about the update thing.
Author
Owner

@github-actions[bot] commented on GitHub (May 4, 2023):

This issue is stale because it has been open for 21 days with no activity.

<!-- gh-comment-id:1533985610 --> @github-actions[bot] commented on GitHub (May 4, 2023): This issue is stale because it has been open for 21 days with no activity.
Author
Owner

@github-actions[bot] commented on GitHub (May 11, 2023):

This issue was closed because it has been inactive for 7 days since being marked as stale.

<!-- gh-comment-id:1543215809 --> @github-actions[bot] commented on GitHub (May 11, 2023): This issue was closed because it has been inactive for 7 days since being marked as stale.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#60
No description provided.