IMAP: add CURLOPT_UPLOAD_FLAGS and --upload-flags

Set properties on the uploaded resource.

Test 3209 and 3210 verify.

Closes #15970
This commit is contained in:
tiymat 2025-01-11 17:20:12 -03:30 committed by Daniel Stenberg
parent 0cd2670afb
commit 6758aa722d
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
25 changed files with 395 additions and 16 deletions

View file

@ -45,6 +45,7 @@ void config_init(struct OperationConfig *config)
config->http09_allowed = FALSE;
config->ftp_skip_ip = TRUE;
config->file_clobber_mode = CLOBBER_DEFAULT;
config->upload_flags = CURLULFLAG_SEEN;
curlx_dyn_init(&config->postdata, MAX_FILE2MEMORY);
}

View file

@ -216,6 +216,7 @@ struct OperationConfig {
CLOBBER_NEVER, /* If the file exists, always fail */
CLOBBER_ALWAYS /* If the file exists, always overwrite it */
} file_clobber_mode;
unsigned char upload_flags; /* Bitmask for --upload-flags */
unsigned short porttouse;
BIT(remote_time);
BIT(cookiesession); /* new session? */

View file

@ -339,6 +339,7 @@ static const struct LongShort aliases[]= {
{"trace-time", ARG_BOOL, ' ', C_TRACE_TIME},
{"unix-socket", ARG_FILE, ' ', C_UNIX_SOCKET},
{"upload-file", ARG_FILE, 'T', C_UPLOAD_FILE},
{"upload-flags", ARG_STRG, ' ', C_UPLOAD_FLAGS},
{"url", ARG_STRG, ' ', C_URL},
{"url-query", ARG_STRG, ' ', C_URL_QUERY},
{"use-ascii", ARG_BOOL, 'B', C_USE_ASCII},
@ -1622,6 +1623,65 @@ static ParameterError parse_time_cond(struct GlobalConfig *global,
return err;
}
struct flagmap {
const char *name;
size_t len;
unsigned char flag;
};
static const struct flagmap flag_table[] = {
{"answered", 8, CURLULFLAG_ANSWERED},
{"deleted", 7, CURLULFLAG_DELETED},
{"draft", 5, CURLULFLAG_DRAFT},
{"flagged", 7, CURLULFLAG_FLAGGED},
{"seen", 4, CURLULFLAG_SEEN},
{NULL, 0, 0}
};
static ParameterError parse_upload_flags(struct OperationConfig *config,
char *nextarg)
{
char *flag;
ParameterError err = PARAM_OK;
char *tmp = strdup(nextarg);
if(!tmp)
return PARAM_NO_MEM;
flag = tmp;
while(flag) {
bool negate;
const struct flagmap *map;
char *next = strchr(flag, ','); /* Find next comma or end */
if(next)
*next++ = '\0';
negate = (*flag == '-');
if(negate)
flag++;
for(map = flag_table; map->name; map++) {
if(!strncmp(flag, map->name, map->len) && flag[map->len] == '\0') {
if(negate)
config->upload_flags &= (unsigned char)~map->flag;
else
config->upload_flags |= map->flag;
break;
}
}
if(!map->name) {
err = PARAM_OPTION_UNKNOWN;
break;
}
flag = next;
}
free(tmp);
return err;
}
ParameterError getparameter(const char *flag, /* f or -long-flag */
char *nextarg, /* NULL if unset */
argv_item_t cleararg1,
@ -2909,6 +2969,9 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
case C_MPTCP: /* --mptcp */
config->mptcp = TRUE;
break;
case C_UPLOAD_FLAGS: /* --upload-flags */
err = parse_upload_flags(config, nextarg);
break;
default: /* unknown flag */
err = PARAM_OPTION_UNKNOWN;
break;

View file

@ -293,6 +293,7 @@ typedef enum {
C_IP_TOS,
C_UNIX_SOCKET,
C_UPLOAD_FILE,
C_UPLOAD_FLAGS,
C_URL,
C_URL_QUERY,
C_USE_ASCII,

View file

@ -808,6 +808,9 @@ const struct helptxt helptext[] = {
{"-T, --upload-file <file>",
"Transfer local FILE to destination",
CURLHELP_IMPORTANT | CURLHELP_UPLOAD},
{" --upload-flags <flags>",
"IMAP upload behavior",
CURLHELP_CURL | CURLHELP_OUTPUT},
{" --url <url/file>",
"URL(s) to work with",
CURLHELP_CURL},

View file

@ -1749,6 +1749,9 @@ static CURLcode config2setopts(struct GlobalConfig *global,
}
#endif
}
/* new in 8.13.0 */
if(config->upload_flags)
my_setopt(curl, CURLOPT_UPLOAD_FLAGS, (long)config->upload_flags);
return result;
}

View file

@ -164,6 +164,7 @@ static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
NV1(CURLOPT_PROXY_SSL_VERIFYPEER, 1),
NV1(CURLOPT_PROXY_SSL_VERIFYHOST, 1),
NV1(CURLOPT_SOCKS5_AUTH, 1),
NV1(CURLOPT_UPLOAD_FLAGS, CURLULFLAG_SEEN),
NVEND
};