Commit 9f726ee0 9f726ee08feeefd295bd5b2e3f6c676d2248f3f5 by Sergey Poznyakoff

mail: Implement folder completion in "save"

* mail/mailline.c (file_compl_internal): New function (from file_compl);
(file_compl): Call file_compl_internal.
(msglist_file_compl): Call file_compl_internal.
1 parent b4d7b1a6
......@@ -291,14 +291,6 @@ msglist_compl (int argc, char **argv, int ws)
}
char **
msglist_file_compl (int argc, char **argv, int ws MU_ARG_UNUSED)
{
if (argc == 1)
ml_attempted_completion_over ();
return NULL;
}
char **
command_compl (int argc, char **argv, int ws)
{
ml_set_completion_append_character (0);
......@@ -413,8 +405,102 @@ folder_generator (const char *text, int state)
return ret;
}
char **
file_compl (int argc, char **argv, int ws)
static char *
msgtype_generator (const char *text, int state)
{
static char types[] = "dnorTtu";
static int i;
char *s;
if (!state)
{
if (text[1])
return NULL;
i = 0;
}
if (!types[i])
return NULL;
s = malloc (2);
if (s)
{
s[0] = types[i++];
s[1] = 0;
}
return s;
}
static char *
header_generator (const char *text, int state)
{
static int i, len;
char *hdr;
char *hdrlist[] = {
MU_HEADER_RETURN_PATH,
MU_HEADER_RECEIVED,
MU_HEADER_DATE,
MU_HEADER_DCC,
MU_HEADER_FROM,
MU_HEADER_SENDER,
MU_HEADER_RESENT_FROM,
MU_HEADER_SUBJECT,
MU_HEADER_RESENT_SENDER,
MU_HEADER_TO,
MU_HEADER_RESENT_TO,
MU_HEADER_CC,
MU_HEADER_RESENT_CC,
MU_HEADER_BCC,
MU_HEADER_RESENT_BCC,
MU_HEADER_REPLY_TO,
MU_HEADER_RESENT_REPLY_TO,
MU_HEADER_MESSAGE_ID,
MU_HEADER_RESENT_MESSAGE_ID,
MU_HEADER_IN_REPLY_TO,
MU_HEADER_REFERENCE,
MU_HEADER_REFERENCES,
MU_HEADER_ENCRYPTED,
MU_HEADER_PRECEDENCE,
MU_HEADER_STATUS,
MU_HEADER_CONTENT_LENGTH,
MU_HEADER_CONTENT_LANGUAGE,
MU_HEADER_CONTENT_TRANSFER_ENCODING,
MU_HEADER_CONTENT_ID,
MU_HEADER_CONTENT_TYPE,
MU_HEADER_CONTENT_DESCRIPTION,
MU_HEADER_CONTENT_DISPOSITION,
MU_HEADER_CONTENT_MD5,
MU_HEADER_CONTENT_LOCATION,
MU_HEADER_MIME_VERSION,
MU_HEADER_X_MAILER,
MU_HEADER_X_UIDL,
MU_HEADER_X_UID,
MU_HEADER_X_IMAPBASE,
MU_HEADER_ENV_SENDER,
MU_HEADER_ENV_DATE,
MU_HEADER_FCC,
MU_HEADER_DELIVERY_DATE,
MU_HEADER_ENVELOPE_TO,
MU_HEADER_X_EXPIRE_TIMESTAMP,
NULL
};
if (!state)
{
i = 0;
len = strlen (text);
}
while ((hdr = hdrlist[i]))
{
i++;
if (mu_c_strncasecmp (hdr, text, len) == 0)
return strdup (hdr);
}
return NULL;
}
static char **
file_compl_internal (int argc, char **argv, int ws, int msglist)
{
char *text;
......@@ -426,12 +512,33 @@ file_compl (int argc, char **argv, int ws)
}
text = argv[argc-1];
if (msglist)
{
if (text[0] == ':')
{
ml_set_completion_append_character (' ');
return rl_completion_matches (text, msgtype_generator);
}
else if (mu_isalpha (text[0]))
{
ml_set_completion_append_character (':');
return rl_completion_matches (text, header_generator);
}
else if (mu_isdigit (text[0]))
{
ml_attempted_completion_over ();
return NULL;
}
}
switch (text[0])
{
case '+':
text++;
break;
case '%':
case '#':
case '&':
ml_attempted_completion_over ();
......@@ -444,6 +551,18 @@ file_compl (int argc, char **argv, int ws)
return rl_completion_matches (text, folder_generator);
}
char **
file_compl (int argc, char **argv, int ws)
{
return file_compl_internal (argc, argv, ws, 0);
}
char **
msglist_file_compl (int argc, char **argv, int ws)
{
return file_compl_internal (argc, argv, ws, 1);
}
static char *
dir_generator (const char *text, int state)
{
......@@ -944,4 +1063,3 @@ ml_attempted_completion_over ()
}
#endif
......