Re: [PATCH v3 2/2] imap-send: create target mailbox if it is missing

2014-08-02 Thread Junio C Hamano
Yup. I think I also queued a fix-up on top.
Thanks for reporting.

On Sat, Aug 2, 2014 at 6:44 AM, Ramsay Jones  wrote:
> On 01/08/14 23:30, Junio C Hamano wrote:
>> Tony Finch  writes:
>>
>>> Some MUAs delete their "drafts" folder when it is empty, so
>>> git imap-send should be able to create it if necessary.
>>
>> Thanks for an update; queued.
>
> BTW, this provokes a warning from gcc (v4.8.2) for me:
>
> CC imap-send.o
> imap-send.c:561:25: warning: ‘issue_imap_cmd’ defined but not used 
> [-Wunused-function]
>  static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
>  ^
> It seems the change to get_cmd_result(), in commit 7ebac713, removes
> the only remaining (two) calls to issue_imap_cmd().
>
> HTH
>
> ATB,
> Ramsay Jones
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/2] imap-send: create target mailbox if it is missing

2014-08-02 Thread Ramsay Jones
On 01/08/14 23:30, Junio C Hamano wrote:
> Tony Finch  writes:
> 
>> Some MUAs delete their "drafts" folder when it is empty, so
>> git imap-send should be able to create it if necessary.
> 
> Thanks for an update; queued.

BTW, this provokes a warning from gcc (v4.8.2) for me:

CC imap-send.o
imap-send.c:561:25: warning: ‘issue_imap_cmd’ defined but not used 
[-Wunused-function]
 static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
 ^
It seems the change to get_cmd_result(), in commit 7ebac713, removes
the only remaining (two) calls to issue_imap_cmd().

HTH

ATB,
Ramsay Jones



--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 2/2] imap-send: create target mailbox if it is missing

2014-08-01 Thread Junio C Hamano
Tony Finch  writes:

> Some MUAs delete their "drafts" folder when it is empty, so
> git imap-send should be able to create it if necessary.

Thanks for an update; queued.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/2] imap-send: create target mailbox if it is missing

2014-08-01 Thread Tony Finch
Some MUAs delete their "drafts" folder when it is empty, so
git imap-send should be able to create it if necessary.

This change checks that the folder exists immediately after
login and tries to create it if it is missing.

There was some vestigial code to handle a [TRYCREATE] response
from the server when an APPEND target is missing. However this
code never ran (the create and trycreate flags were never set)
and when I tried to make it run I found that the code had already
thrown away the contents of the message it was trying to append.

Signed-off-by: Tony Finch 
---
 imap-send.c | 57 ++---
 1 file changed, 26 insertions(+), 31 deletions(-)

diff --git a/imap-send.c b/imap-send.c
index 524fbab..a29d03e 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -128,7 +128,6 @@ struct imap_cmd_cb {
char *data;
int dlen;
int uid;
-   unsigned create:1, trycreate:1;
 };

 struct imap_cmd {
@@ -714,8 +713,8 @@ static int parse_response_code(struct imap_store *ctx, 
struct imap_cmd_cb *cb,
 static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
 {
struct imap *imap = ctx->imap;
-   struct imap_cmd *cmdp, **pcmdp, *ncmdp;
-   char *cmd, *arg, *arg1, *p;
+   struct imap_cmd *cmdp, **pcmdp;
+   char *cmd, *arg, *arg1;
int n, resp, resp2, tag;

for (;;) {
@@ -801,30 +800,9 @@ static int get_cmd_result(struct imap_store *ctx, struct 
imap_cmd *tcmd)
if (!strcmp("OK", arg))
resp = DRV_OK;
else {
-   if (!strcmp("NO", arg)) {
-   if (cmdp->cb.create && cmd && 
(cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or 
UID COPY */
-   p = strchr(cmdp->cmd, '"');
-   if (!issue_imap_cmd(ctx, NULL, 
"CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
-   resp = RESP_BAD;
-   goto normal;
-   }
-   /* not waiting here violates 
the spec, but a server that does not
-  grok this nonetheless 
violates it too. */
-   cmdp->cb.create = 0;
-   if (!(ncmdp = 
issue_imap_cmd(ctx, &cmdp->cb, "%s", cmdp->cmd))) {
-   resp = RESP_BAD;
-   goto normal;
-   }
-   free(cmdp->cmd);
-   free(cmdp);
-   if (!tcmd)
-   return 0;   /* 
ignored */
-   if (cmdp == tcmd)
-   tcmd = ncmdp;
-   continue;
-   }
+   if (!strcmp("NO", arg))
resp = RESP_NO;
-   } else /*if (!strcmp("BAD", arg))*/
+   else /*if (!strcmp("BAD", arg))*/
resp = RESP_BAD;
fprintf(stderr, "IMAP command '%s' returned 
response (%s) - %s\n",
 memcmp(cmdp->cmd, "LOGIN", 5) ?
@@ -833,7 +811,6 @@ static int get_cmd_result(struct imap_store *ctx, struct 
imap_cmd *tcmd)
}
if ((resp2 = parse_response_code(ctx, &cmdp->cb, cmd)) 
> resp)
resp = resp2;
-   normal:
if (cmdp->cb.done)
cmdp->cb.done(ctx, cmdp, resp);
free(cmdp->cb.data);
@@ -944,7 +921,7 @@ static int auth_cram_md5(struct imap_store *ctx, struct 
imap_cmd *cmd, const cha
return 0;
 }

-static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
+static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char 
*folder)
 {
struct credential cred = CREDENTIAL_INIT;
struct imap_store *ctx;
@@ -1156,6 +1133,25 @@ static struct imap_store *imap_open_store(struct 
imap_server_conf *srvc)
credential_approve(&cred);
credential_clear(&cred);

+   /* check the target mailbox exists */
+   ctx->name = folder;
+   switch (imap_exec(ctx, NULL, "EXAMINE \"%s\"", ctx->name)) {
+   case RESP_OK:
+   /* ok */
+   bre