Changeset 1414:f8449f93c867

Show
Ignore:
Timestamp:
1999-12-09 03:17:04 (9 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Tommi Komulainen's multiple IMAP usernames patch.

Files:
14 modified

Legend:

Unmodified
Added
Removed
  • browser.c

    r1383 r1414  
    809809        { 
    810810          char msg[LONG_STRING]; 
    811           char* mbox; 
     811          IMAP_MBOX mx; 
    812812          int nentry = menu->current; 
    813813           
    814           imap_parse_path (state.entry[nentry].name, NULL, 0, NULL, 
    815             NULL, &mbox); 
     814          imap_parse_path (state.entry[nentry].name, &mx); 
    816815          snprintf (msg, sizeof (msg), _("Really delete mailbox \"%s\"?"), 
    817             mbox); 
     816            mx.mbox); 
    818817          if (mutt_yesorno (msg, M_NO) == M_YES) 
    819818          { 
    820             if (!imap_delete_mailbox (Context, mbox)) 
     819            if (!imap_delete_mailbox (Context, mx.mbox)) 
    821820            { 
    822821              /* free the mailbox from the browser */ 
  • doc/manual.sgml.head

    r1410 r1414  
    19601960<tt/{imapserver:port}inbox/. 
    19611961 
     1962You can also specify different username for each folder, ie: 
     1963<tt/{username@imapserver[:port]}inbox/. 
     1964 
    19621965If Mutt was compiled with SSL support (by running the <em/configure/ 
    19631966script with the <em/--enable-ssl/ flag), connections to IMAP servers 
    19641967can be encrypted. This naturally requires that the server supports 
    19651968SSL encrypted connections. To access a folder with IMAP/SSL, you should 
    1966 use <tt>{imapserver[:port]/ssl}path/to/folder</tt> as your  
     1969use <tt>{[username@]imapserver[:port]/ssl}path/to/folder</tt> as your  
    19671970folder path. 
    19681971 
  • imap/README

    r1383 r1414  
    2727* Preserve deleted messages if you don't choose to expunge them 
    2828* Delete mailboxes (from the browser) 
     29* Multiple IMAP usernames 
  • imap/auth.c

    r1334 r1414  
    122122 
    123123  /* get an IMAP service ticket for the server */ 
    124   snprintf (buf1, sizeof (buf1), "imap@%s", idata->conn->server); 
     124  snprintf (buf1, sizeof (buf1), "imap@%s", idata->conn->mx.host); 
    125125  request_buf.value = buf1; 
    126126  request_buf.length = strlen (buf1) + 1; 
    … …  
    478478  while (r != 0) 
    479479  { 
    480     if (!ImapUser) 
    481     { 
    482       strfcpy (user, NONULL(Username), sizeof (user)); 
    483       if (mutt_get_field (_("IMAP Username: "), user, sizeof (user), 0) != 0) 
    484       { 
    485         user[0] = 0; 
    486         return (-1); 
    487       } 
     480    if (! (conn->mx.flags & M_IMAP_USER)) 
     481    { 
     482      if (!ImapUser) 
     483      { 
     484        strfcpy (user, NONULL(Username), sizeof (user)); 
     485        if (mutt_get_field (_("IMAP Username: "), user, sizeof (user), 0) != 0) 
     486        { 
     487          user[0] = 0; 
     488          return (-1); 
     489        } 
     490      } 
     491      else 
     492        strfcpy (user, ImapUser, sizeof (user)); 
    488493    } 
    489494    else 
    490       strfcpy (user, ImapUser, sizeof (user)); 
     495      strfcpy (user, conn->mx.user, sizeof (user)); 
    491496 
    492497    if (!user[0]) 
    … …  
    520525    if (mutt_bit_isset (idata->capabilities, ACRAM_MD5)) 
    521526    { 
    522       if (!ImapCRAMKey) 
    523       { 
    524         ckey[0] = '\0'; 
    525         snprintf (buf, sizeof (buf), _("CRAM key for %s@%s: "), user, 
    526           conn->server); 
    527         if (mutt_get_field (buf, ckey, sizeof (ckey), M_PASS) != 0) 
    528           return -1; 
     527      if (!(conn->mx.flags & M_IMAP_CRAM)) 
     528      { 
     529        if (!ImapCRAMKey) 
     530        { 
     531          ckey[0] = '\0'; 
     532          snprintf (buf, sizeof (buf), _("CRAM key for %s@%s: "), user, 
     533                    conn->mx.host); 
     534          if (mutt_get_field (buf, ckey, sizeof (ckey), M_PASS) != 0) 
     535            return -1; 
     536        } 
     537        else 
     538          strfcpy (ckey, ImapCRAMKey, sizeof (ckey)); 
    529539      } 
    530540      else 
    531         strfcpy (ckey, ImapCRAMKey, sizeof (ckey)); 
     541        strfcpy (ckey, conn->mx.pass, sizeof (ckey)); 
    532542 
    533543      if (*ckey) 
    … …  
    537547          mutt_error _("CRAM-MD5 authentication failed."); 
    538548          sleep (1); 
     549          if (!(conn->mx.flags & M_IMAP_CRAM)) 
     550            FREE (&ImapCRAMKey); 
     551          conn->mx.flags &= ~M_IMAP_CRAM; 
    539552        } 
    540553        else 
     554        { 
     555          strfcpy (conn->mx.pass, ckey, sizeof (conn->mx.pass)); 
     556          conn->mx.flags |= M_IMAP_CRAM; 
    541557          return 0; 
     558        } 
    542559      } 
    543560      else 
    … …  
    550567      dprint (2, (debugfile, "CRAM-MD5 authentication is not available\n")); 
    551568         
    552     if (!ImapPass) 
    553     { 
    554       pass[0]=0; 
    555       snprintf (buf, sizeof (buf), _("Password for %s@%s: "), user, conn->server); 
    556       if (mutt_get_field (buf, pass, sizeof (pass), M_PASS) != 0 || 
    557           !pass[0]) 
    558       { 
    559         return (-1); 
    560       } 
     569    if (! (conn->mx.flags & M_IMAP_PASS)) 
     570    { 
     571      if (!ImapPass) 
     572      { 
     573        pass[0]=0; 
     574        snprintf (buf, sizeof (buf), _("Password for %s@%s: "), user, conn->mx.host); 
     575        if (mutt_get_field (buf, pass, sizeof (pass), M_PASS) != 0 || 
     576            !pass[0]) 
     577        { 
     578          return (-1); 
     579        } 
     580      } 
     581      else 
     582        strfcpy (pass, ImapPass, sizeof (pass)); 
    561583    } 
    562584    else 
    563       strfcpy (pass, ImapPass, sizeof (pass)); 
     585      strfcpy (pass, conn->mx.pass, sizeof (pass)); 
    564586 
    565587    imap_quote_string (q_user, sizeof (q_user), user); 
    … …  
    581603      sleep (1); 
    582604 
    583       FREE (&ImapUser); 
    584       FREE (&ImapPass); 
     605      if (!(conn->mx.flags & M_IMAP_USER)) 
     606        FREE (&ImapUser); 
     607      if (!(conn->mx.flags & M_IMAP_PASS)) 
     608        FREE (&ImapPass); 
     609      conn->mx.flags &= ~M_IMAP_PASS; 
    585610    } 
    586611    else 
    … …  
    588613      /* If they have a successful login, we may as well cache the  
    589614       * user/password. */ 
    590       if (!ImapUser) 
    591         ImapUser = safe_strdup (user); 
    592       if (!ImapPass) 
    593         ImapPass = safe_strdup (pass); 
     615      if (!(conn->mx.flags & M_IMAP_USER)) 
     616        strfcpy (conn->mx.user, user, sizeof (conn->mx.user)); 
     617      if (!(conn->mx.flags & M_IMAP_PASS)) 
     618        strfcpy (conn->mx.pass, pass, sizeof (conn->mx.pass)); 
     619       
     620      conn->mx.flags |= (M_IMAP_USER | M_IMAP_PASS); 
    594621    } 
    595622  } 
  • imap/browse.c

    r1373 r1414  
    4444  char nsbuf[LONG_STRING]; 
    4545  char mbox[LONG_STRING]; 
    46   char host[SHORT_STRING]; 
    47   int port; 
    4846  char list_cmd[5]; 
    4947  char seq[16]; 
    50   char *ipath = NULL; 
    5148  IMAP_NAMESPACE_INFO nsi[16]; 
    5249  int home_namespace = 0; 
    … …  
    6057  int noselect; 
    6158  int noinferiors; 
    62  
    63   if (imap_parse_path (path, host, sizeof (host), &port, NULL, &ipath)) 
     59  IMAP_MBOX mx; 
     60 
     61  if (imap_parse_path (path, &mx)) 
    6462  { 
    6563    mutt_error ("%s is an invalid IMAP path", path); 
    … …  
    6967  strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd)); 
    7068 
    71   conn = mutt_socket_select_connection (host, port, 0); 
     69  conn = mutt_socket_select_connection (&mx, 0); 
    7270  idata = CONN_DATA; 
    7371 
    … …  
    8583  } 
    8684 
    87   if (ipath[0] == '\0') 
     85  if (mx.mbox[0] == '\0') 
    8886  { 
    8987    home_namespace = 1; 
    9088    mbox[0] = 0;                /* Do not replace "" with "INBOX" here */ 
    91     ipath = ImapHomeNamespace; 
     89    mx.mbox = ImapHomeNamespace; 
    9290    nns = 0; 
    9391    if (mutt_bit_isset(idata->capabilities,NAMESPACE)) 
    … …  
    9997        return (-1); 
    10098    } 
    101     if (!ipath)         /* Any explicitly set imap_home_namespace wins */ 
     99    if (!mx.mbox)               /* Any explicitly set imap_home_namespace wins */ 
    102100    {  
    103101      for (i = 0; i < nns; i++) 
    … …  
    105103            (nsi[i].type == IMAP_NS_PERSONAL || nsi[i].type == IMAP_NS_SHARED)) 
    106104        { 
    107           ipath = nsi->prefix; 
     105          mx.mbox = nsi->prefix; 
    108106          nsi->home_namespace = 1; 
    109107          break; 
    … …  
    114112  mutt_message _("Contacted server, getting folder list..."); 
    115113 
    116   if (ipath && ipath[0] != '\0') 
    117   { 
    118     imap_fix_path (idata, ipath, mbox, sizeof (mbox)); 
     114  if (mx.mbox && mx.mbox[0] != '\0') 
     115  { 
     116    imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox)); 
    119117    n = mutt_strlen (mbox); 
    120118 
    … …  
    154152    { 
    155153      showparents = 1; 
    156       imap_qualify_path (buf, sizeof (buf), host, port, mbox, NULL); 
     154      imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL); 
    157155      state->folder = safe_strdup (buf); 
    158156      n--; 
    … …  
    183181        ctmp = mbox[n]; 
    184182        mbox[n] = '\0'; 
    185         imap_qualify_path (buf, sizeof (buf), host, port, mbox, NULL); 
     183        imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL); 
    186184        state->folder = safe_strdup (buf); 
    187185      } 
    … …  
    198196      if (!state->folder) 
    199197      { 
    200         imap_qualify_path (buf, sizeof (buf), host, port, relpath, NULL); 
     198        imap_qualify_path (buf, sizeof (buf), &mx, relpath, NULL); 
    201199        state->folder = safe_strdup (buf); 
    202200      } 
    … …  
    207205  if (!state->folder) 
    208206  { 
    209     imap_qualify_path (buf, sizeof (buf), host, port, NULL, NULL); 
     207    imap_qualify_path (buf, sizeof (buf), &mx, NULL, NULL); 
    210208    state->folder = safe_strdup (buf); 
    211209  } 
    … …  
    249247  IMAP_DATA *idata = CONN_DATA; 
    250248  char buf[LONG_STRING]; 
    251   char host[SHORT_STRING]; 
    252   int port; 
    253   char *curfolder; 
    254249  char *name; 
    255250  int noselect; 
    256251  int noinferiors; 
    257  
    258   if (imap_parse_path (state->folder, host, sizeof (host), &port, NULL, &curfolder)) 
     252  IMAP_MBOX mx; 
     253 
     254  if (imap_parse_path (state->folder, &mx)) 
    259255  { 
    260256    dprint (2, (debugfile, 
    … …  
    278274        noselect = 1; 
    279275      /* prune current folder from output */ 
    280       if (isparent || strncmp (name, curfolder, strlen (name))) 
     276      if (isparent || strncmp (name, mx.mbox, strlen (name))) 
    281277        imap_add_folder (idata->delim, name, noselect, noinferiors, state, 
    282278          isparent); 
    … …  
    295291  char tmp[LONG_STRING]; 
    296292  char relpath[LONG_STRING]; 
    297   char host[SHORT_STRING]; 
    298   int port; 
    299   char *curfolder; 
    300293  int flen = strlen (folder); 
    301  
    302   if (imap_parse_path (state->folder, host, sizeof (host), &port, NULL, &curfolder)) 
     294  IMAP_MBOX mx; 
     295 
     296  if (imap_parse_path (state->folder, &mx)) 
    303297    return; 
    304298 
    … …  
    321315    strfcpy (relpath, "../", sizeof (relpath)); 
    322316  /* strip current folder from target, to render a relative path */ 
    323   else if (!strncmp (curfolder, folder, strlen (curfolder))) 
    324     strfcpy (relpath, folder + strlen (curfolder), sizeof (relpath)); 
     317  else if (!strncmp (mx.mbox, folder, strlen (mx.mbox))) 
     318    strfcpy (relpath, folder + strlen (mx.mbox), sizeof (relpath)); 
    325319  else 
    326320    strfcpy (relpath, folder, sizeof (relpath)); 
    … …  
    334328  if (!noselect) 
    335329  { 
    336     imap_qualify_path (tmp, sizeof (tmp), host, port, folder, NULL); 
     330    imap_qualify_path (tmp, sizeof (tmp), &mx, folder, NULL); 
    337331    (state->entry)[state->entrylen].name = safe_strdup (tmp); 
    338332 
    … …  
    350344    trailing_delim[0] = (flen && folder[flen - 1] != delim) ? delim : '\0'; 
    351345 
    352     imap_qualify_path (tmp, sizeof (tmp), host, port, folder, trailing_delim); 
     346    imap_qualify_path (tmp, sizeof (tmp), &mx, folder, trailing_delim); 
    353347    (state->entry)[state->entrylen].name = safe_strdup (tmp); 
    354348 
  • imap/imap.c

    r1383 r1414  
    538538  char buf[LONG_STRING]; 
    539539  char bufout[LONG_STRING]; 
    540   char host[SHORT_STRING]; 
    541540  char seq[16]; 
    542   char *pc = NULL; 
    543541  int count = 0; 
    544542  int n; 
    545   int port; 
    546   int socktype; 
    547  
    548   if (imap_parse_path (ctx->path, host, sizeof (host), &port, &socktype, &pc)) 
     543  IMAP_MBOX mx; 
     544   
     545  if (imap_parse_path (ctx->path, &mx)) 
    549546  { 
    550547    mutt_error ("%s is an invalid IMAP path", ctx->path); 
    … …  
    552549  } 
    553550 
    554   conn = mutt_socket_select_connection (host, port, 0); 
     551  conn = mutt_socket_select_connection (&mx, 0); 
    555552  idata = CONN_DATA; 
    556553 
    … …  
    563560      idata = safe_calloc (1, sizeof (IMAP_DATA)); 
    564561 
    565       conn = mutt_socket_select_connection (host, port, socktype); 
     562      conn = mutt_socket_select_connection (&mx, 1); 
    566563      conn->data = idata; 
    567564      idata->conn = conn; 
    … …  
    573570 
    574571  /* Clean up path and replace the one in the ctx */ 
    575   imap_fix_path (idata, pc, buf, sizeof (buf)); 
     572  imap_fix_path (idata, mx.mbox, buf, sizeof (buf)); 
    576573  FREE(&(idata->selected_mailbox)); 
    577574  idata->selected_mailbox = safe_strdup (buf); 
    578   imap_qualify_path (buf, sizeof (buf), host, port, idata->selected_mailbox, 
     575  imap_qualify_path (buf, sizeof (buf), &mx, idata->selected_mailbox, 
    579576    NULL); 
    580577 
    … …  
    598595  do 
    599596  { 
     597    char *pc; 
     598     
    600599    if (mutt_socket_read_line_d (buf, sizeof (buf), conn) < 0) 
    601600      break; 
    … …  
    713712  IMAP_DATA* idata; 
    714713  CONNECTION* conn; 
    715   char host[SHORT_STRING]; 
    716   int port; 
    717714  char curpath[LONG_STRING]; 
    718   char* mbox = NULL; 
     715  IMAP_MBOX mx; 
    719716 
    720717  strfcpy (curpath, path, sizeof (curpath)); 
    721718  /* check that the target folder makes sense */ 
    722   if (imap_parse_path (curpath, host, sizeof (host), &port, NULL, &mbox)) 
     719  if (imap_parse_path (curpath, &mx)) 
    723720    return -1; 
    724721 
    725722  /* and that it's on the same server as the current folder */ 
    726   conn = mutt_socket_select_connection (host, port, 0); 
     723  conn = mutt_socket_select_connection (&mx, 0); 
    727724  if (!CTX_DATA || !CONN_DATA || (CTX_DATA->conn != CONN_DATA->conn)) 
    728725  { 
    … …  
    748745  CONNECTION *conn; 
    749746  IMAP_DATA *idata; 
    750   char host[SHORT_STRING]; 
    751747  char buf[LONG_STRING], mbox[LONG_STRING]; 
    752748  char mailbox[LONG_STRING]; 
    753   char *pc; 
    754749  int r; 
    755   int port; 
    756   int socktype; 
    757  
    758   if (imap_parse_path (ctx->path, host, sizeof (host), &port, &socktype, &pc)) 
     750  IMAP_MBOX mx; 
     751 
     752  if (imap_parse_path (ctx->path, &mx)) 
    759753    return (-1); 
    760754 
    761755  ctx->magic = M_IMAP; 
    762756 
    763   conn = mutt_socket_select_connection (host, port, 0); 
     757  conn = mutt_socket_select_connection (&mx, 0); 
    764758  idata = CONN_DATA; 
    765759 
    … …  
    780774  /* check mailbox existance */ 
    781775 
    782   imap_fix_path (idata, pc, mailbox, sizeof (mailbox)); 
     776  imap_fix_path (idata, mx.mbox, mailbox, sizeof (mailbox)); 
    783777 
    784778  imap_quote_string (mbox, sizeof (mbox), mailbox); 
    … …  
    11681162  CONNECTION *conn; 
    11691163  IMAP_DATA *idata; 
    1170   char host[SHORT_STRING]; 
    11711164  char buf[LONG_STRING]; 
    11721165  char mbox[LONG_STRING]; 
    … …  
    11741167  char seq[8]; 
    11751168  char *s; 
    1176   char *pc; 
    11771169  int msgcount = 0; 
    1178   int port; 
    1179  
    1180   if (imap_parse_path (path, host, sizeof (host), &port, NULL, &pc)) 
    1181     return -1; 
    1182  
    1183   conn = mutt_socket_select_connection (host, port, 0); 
     1170  IMAP_MBOX mx; 
     1171   
     1172  if (imap_parse_path (path, &mx)) 
     1173    return -1; 
     1174 
     1175  conn = mutt_socket_select_connection (&mx, 0); 
    11841176  idata = CONN_DATA; 
    11851177 
    … …  
    12011193  } 
    12021194 
    1203   imap_fix_path (idata, pc, buf, sizeof (buf)); 
     1195  imap_fix_path (idata, mx.mbox, buf, sizeof (buf)); 
    12041196  /* Update the path, if it fits */ 
    1205   if (strlen (buf) < strlen (pc)) 
    1206       strcpy (pc, buf); 
     1197  if (strlen (buf) < strlen (mx.mbox)) 
     1198      strcpy (mx.mbox, buf); 
    12071199 
    12081200  imap_make_sequence (seq, sizeof (seq));               Â 
    … …  
    13591351  char buf[LONG_STRING]; 
    13601352  char mbox[LONG_STRING]; 
    1361   char host[SHORT_STRING]; 
    1362   char *ipath = NULL; 
    1363   int port; 
    1364  
    1365   if (imap_parse_path (path, host, sizeof (host), &port, NULL, &ipath)) 
     1353  IMAP_MBOX mx; 
     1354 
     1355  if (imap_parse_path (path, &mx)) 
    13661356    return (-1); 
    13671357 
    1368   conn = mutt_socket_select_connection (host, port, 0); 
     1358  conn = mutt_socket_select_connection (&mx, 0); 
    13691359  idata = CONN_DATA; 
    13701360 
    … …  
    13821372  } 
    13831373 
    1384   imap_fix_path (idata, ipath, buf, sizeof (buf)); 
     1374  imap_fix_path (idata, mx.mbox, buf, sizeof (buf)); 
    13851375  if (subscribe) 
    13861376    mutt_message (_("Subscribing to %s..."), buf); 
    … …  
    14031393  CONNECTION* conn; 
    14041394  IMAP_DATA* idata; 
    1405   char host[SHORT_STRING]; 
    1406   int port; 
    14071395  char list[LONG_STRING]; 
    14081396  char buf[LONG_STRING]; 
    14091397  char seq[16]; 
    1410   char* mbox = NULL; 
    14111398  char* list_word = NULL; 
    14121399  int noselect, noinferiors; 
    … …  
    14161403  int completions = 0; 
    14171404  int pos = 0; 
     1405  IMAP_MBOX mx; 
    14181406 
    14191407  /* verify passed in path is an IMAP path */ 
    1420   if (imap_parse_path (path, host, sizeof(host), &port, NULL, &mbox)) 
     1408  if (imap_parse_path (path, &mx)) 
    14211409  { 
    14221410    dprint(2, (debugfile, "imap_complete: bad path %s\n", path)); 
    … …  
    14241412  } 
    14251413 
    1426   conn = mutt_socket_select_connection (host, port, 0); 
     1414  conn = mutt_socket_select_connection (&mx, 0); 
    14271415  idata = CONN_DATA; 
    14281416 
    … …  
    14371425  /* reformat path for IMAP list, and append wildcard */ 
    14381426  /* don't use INBOX in place of "" */ 
    1439   if (mbox[0]) 
    1440     imap_fix_path (idata, mbox, list, sizeof(list)); 
     1427  if (mx.mbox[0]) 
     1428    imap_fix_path (idata, mx.mbox, list, sizeof(list)); 
    14411429  else 
    14421430    list[0] = '\0'; 
    … …  
    14491437 
    14501438  /* and see what the results are */ 
    1451   strfcpy (completion, mbox, sizeof(completion)); 
     1439  strfcpy (completion, mx.mbox, sizeof(completion)); 
    14521440  do 
    14531441  { 
    … …  
    14931481  { 
    14941482    /* reformat output */ 
    1495     imap_qualify_path (dest, dlen, host, port, completion, NULL); 
     1483    imap_qualify_path (dest, dlen, &mx, completion, NULL); 
    14961484    mutt_pretty_mailbox (dest); 
    14971485 
  • imap/imap.h

    r1397 r1414  
    2222#include "browser.h" 
    2323#include "mailbox.h" 
     24 
     25typedef struct 
     26{ 
     27  char user[32]; 
     28  char pass[32]; 
     29  char host[128]; 
     30  int port; 
     31  char type[16]; 
     32  int socktype; 
     33  char *mbox; 
     34  int flags; 
     35} IMAP_MBOX; 
     36 
    2437 
    2538/* imap.c */ 
    … …  
    4861 
    4962/* util.c */ 
    50 int imap_parse_path (char* path, char* host, size_t hlen, int* port, 
    51   int *socktype, char** mbox); 
    52 void imap_qualify_path (char* dest, size_t len, const char* host, int port, 
     63int imap_parse_path (const char* path, IMAP_MBOX *mx); 
     64void imap_qualify_path (char* dest, size_t len, const IMAP_MBOX *mx, 
    5365  const char* path, const char* name); 
    5466 
  • imap/imap_private.h

    r1383 r1414  
    3232 
    3333#define SEQLEN 5 
     34 
     35#define M_IMAP_USER (1<<0) 
     36#define M_IMAP_PORT (1<<1) 
    Â