Hi!
So I am writing, of all things, a batch file that creates a multipart MIME message body. Part of that is looking at a file name and determining its MIME type. The file name is given like so:
To extract the MIME type from the filename+type in
If the MIME type is not specified or empty, the subroutine doing the parsing tries to infer the type, SWITCHing on the file extension:
Please note the attempts at regular expressions. I realise that I could just write
If any of you know whether
So I am writing, of all things, a batch file that creates a multipart MIME message body. Part of that is looking at a file name and determining its MIME type. The file name is given like so:
pathandfile[:mime/type]
. A few examples of valid filenames, some with MIME types, some without:
Code:
thatdir\userdata.yaml:text/yaml
thatdir\userdata.yaml
c:\cloudconfig\otherdir\configsamba.sh:text/x-shellscript
c:\cloudconfig\otherdir\configsumtin.sh
w
, I use
Code:
set mimetype=%@regexsub[2,^^(.*):([^^:/]*/[^^:/]*)$,%@unquotes[%[w]]]
Code:
switch "%@ext[%[getfilename_filename]]"
case "yaml" .or. "yml"
set getfilename_mimetype=text/cloud-config
case "(b|ba|c|k|z)?sh"
set getfilename_mimetype=text/x-shellscript
case /"(b|ba|c|k|z)?sh"/
set getfilename_mimetype=text/x-shellscript
case "::("?)(b|ba|c|k|z)?sh\1"
set getfilename_mimetype=text/x-shellscript
default
echo Cannot infer MIME type for file %[getfilename_filename]
set getfilename_rc=2
set getfilename_mimetype=text/plain
endswitch
CASE "sh" .or. "bsh" .or. "csh" .or. …
, but the SWITCH documentation for TCC (27.01.23) expressly states:and I confess to being curious.https://jpsoft.com/help/switch.htm said:CASE statements can include wildcards and regular expressions.
If any of you know whether
CASE
accepts regexes and wildcards, and if so, how to bring that about, I would be very grateful. Thanks!