~ubuntu-dev/ubuntu/lucid/mutt/lucid-201002110857

« back to all changes in this revision

Viewing changes to imap/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-06-07 17:30:03 UTC
  • mto: (16.2.1 experimental) (2.3.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090607173003-rg37ui3h2bbv7wl0
Tags: upstream-1.5.19
ImportĀ upstreamĀ versionĀ 1.5.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
3
3
 * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
4
 
 * Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>
 
4
 * Copyright (C) 1999-2008 Brendan Cully <brendan@kublai.com>
5
5
 * 
6
6
 *     This program is free software; you can redistribute it and/or modify
7
7
 *     it under the terms of the GNU General Public License as published by
26
26
#include "mx.h" /* for M_IMAP */
27
27
#include "url.h"
28
28
#include "imap_private.h"
29
 
#include "mutt_ssl.h"
30
29
#ifdef USE_HCACHE
31
30
#include "message.h"
32
31
#include "hcache.h"
56
55
{
57
56
  IMAP_MBOX mx;
58
57
  ciss_url_t url;
 
58
  char fixedpath[LONG_STRING];
59
59
  int rc;
60
60
 
61
61
  if (imap_parse_path (path, &mx) < 0)
62
62
    return -1;
63
63
 
64
64
  mutt_account_tourl (&mx.account, &url);
65
 
  url.path = mx.mbox;
 
65
  imap_fix_path(NULL, mx.mbox, fixedpath, sizeof (fixedpath));
 
66
  url.path = fixedpath;
66
67
 
67
68
  rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD);
68
69
  FREE (&mx.mbox);
189
190
  }
190
191
 
191
192
  /* Defaults */
192
 
  mx->account.flags = 0;
 
193
  memset(&mx->account, 0, sizeof(mx->account));
193
194
  mx->account.port = ImapPort;
194
195
  mx->account.type = M_ACCT_TYPE_IMAP;
195
196
 
354
355
  if (!(idata->cmdbuf = mutt_buffer_init (NULL)))
355
356
    FREE (&idata);
356
357
 
 
358
  idata->cmdslots = ImapPipelineDepth + 2;
 
359
  if (!(idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds))))
 
360
  {
 
361
    mutt_buffer_free(&idata->cmdbuf);
 
362
    FREE (&idata);
 
363
  }
 
364
 
357
365
  return idata;
358
366
}
359
367
 
369
377
  mutt_buffer_free(&(*idata)->cmdbuf);
370
378
  FREE (&(*idata)->buf);
371
379
  mutt_bcache_close (&(*idata)->bcache);
 
380
  FREE (&(*idata)->cmds);
372
381
  FREE (idata);         /* __FREE_CHECKED__ */
373
382
}
374
383
 
383
392
char *imap_fix_path (IMAP_DATA *idata, char *mailbox, char *path, 
384
393
    size_t plen)
385
394
{
386
 
  int x = 0;
 
395
  int i = 0;
 
396
  char delim;
 
397
  
 
398
  if (idata)
 
399
    delim = idata->delim;
 
400
  else if (ImapDelimChars && ImapDelimChars[0])
 
401
    delim = ImapDelimChars[0];
 
402
  else
 
403
    delim = '/';
387
404
 
388
 
  while (mailbox && *mailbox && (x < (plen - 1)))
 
405
  while (mailbox && *mailbox && i < plen - 1)
389
406
  {
390
 
    if ((*mailbox == '/') || (*mailbox == idata->delim))
 
407
    if (strchr(ImapDelimChars, *mailbox) || *mailbox == delim)
391
408
    {
392
 
      while ((*mailbox == '/') || (*mailbox == idata->delim)) mailbox++;
393
 
      path[x] = idata->delim;
 
409
      while (*mailbox &&
 
410
             (strchr(ImapDelimChars, *mailbox) || *mailbox == delim))
 
411
        mailbox++;
 
412
      path[i] = delim;
394
413
    }
395
414
    else
396
415
    {
397
 
      path[x] = *mailbox;
 
416
      path[i] = *mailbox;
398
417
      mailbox++;
399
418
    }
400
 
    x++;
 
419
    i++;
401
420
  }
402
 
  if (x && path[--x] != idata->delim)
403
 
    x++;
404
 
  path[x] = '\0';
405
 
 
406
 
  if (!path[0])
407
 
    strfcpy (path, "INBOX", plen);
 
421
  if (i && path[--i] != delim)
 
422
    i++;
 
423
  path[i] = '\0';
408
424
 
409
425
  return path;
410
426
}
773
789
  if (ctx && ctx->magic == M_IMAP && CTX_DATA->ctx == ctx)
774
790
    CTX_DATA->reopen &= ~IMAP_REOPEN_ALLOW;
775
791
}
 
792
 
 
793
int imap_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
 
794
{
 
795
  IMAP_DATA* a1_idata = imap_conn_find (a1, M_IMAP_CONN_NONEW);
 
796
  IMAP_DATA* a2_idata = imap_conn_find (a2, M_IMAP_CONN_NONEW);
 
797
  const ACCOUNT* a1_canon = a1_idata == NULL ? a1 : &a1_idata->conn->account;
 
798
  const ACCOUNT* a2_canon = a2_idata == NULL ? a2 : &a2_idata->conn->account;
 
799
 
 
800
  return mutt_account_match (a1_canon, a2_canon);
 
801
}