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

« back to all changes in this revision

Viewing changes to smtp.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
/* mutt - text oriented MIME mail user agent
2
2
 * Copyright (C) 2002 Michael R. Elkins <me@mutt.org>
3
 
 * Copyright (C) 2005-7 Brendan Cully <brendan@kublai.com>
 
3
 * Copyright (C) 2005-9 Brendan Cully <brendan@kublai.com>
4
4
 *
5
5
 *     This program is free software; you can redistribute it and/or modify
6
6
 *     it under the terms of the GNU General Public License as published by
89
89
 
90
90
  do {
91
91
    n = mutt_socket_readln (buf, sizeof (buf), conn);
92
 
    if (n == -1)
 
92
    if (n < 4) {
 
93
      /* read error, or no response code */
93
94
      return smtp_err_read;
94
 
    n = atoi (buf);
 
95
    }
95
96
 
96
97
    if (!ascii_strncasecmp ("8BITMIME", buf + 4, 8))
97
98
      mutt_bit_set (Capabilities, EIGHTBITMIME);
98
 
    else if (!ascii_strncasecmp ("AUTH", buf + 4, 4))
 
99
    else if (!ascii_strncasecmp ("AUTH ", buf + 4, 5))
99
100
    {
100
101
      mutt_bit_set (Capabilities, AUTH);
101
102
      FREE (&AuthMechs);
105
106
      mutt_bit_set (Capabilities, DSN);
106
107
    else if (!ascii_strncasecmp ("STARTTLS", buf + 4, 8))
107
108
      mutt_bit_set (Capabilities, STARTTLS);
 
109
 
 
110
    n = atoi (buf);
108
111
  } while (buf[3] == '-');
109
112
 
110
113
  if (smtp_success (n) || n == smtp_continue)
210
213
{
211
214
  CONNECTION *conn;
212
215
  ACCOUNT account;
 
216
  const char* envfrom;
 
217
  char buf[1024];
213
218
  int ret = -1;
214
 
  char buf[1024];
 
219
 
 
220
  /* it might be better to synthesize an envelope from from user and host
 
221
   * but this condition is most likely arrived at accidentally */
 
222
  if (EnvFrom)
 
223
    envfrom = EnvFrom->mailbox;
 
224
  else if (from)
 
225
    envfrom = from->mailbox;
 
226
  else
 
227
  {
 
228
    mutt_error (_("No from address given"));
 
229
    return -1;
 
230
  }
215
231
 
216
232
  if (smtp_fill_account (&account) < 0)
217
233
    return ret;
229
245
    FREE (&AuthMechs);
230
246
 
231
247
    /* send the sender's address */
232
 
    ret = snprintf (buf, sizeof (buf), "MAIL FROM:<%s>",
233
 
                    EnvFrom ? EnvFrom->mailbox : from->mailbox);
 
248
    ret = snprintf (buf, sizeof (buf), "MAIL FROM:<%s>", envfrom);
234
249
    if (eightbit && mutt_bit_isset (Capabilities, EIGHTBITMIME))
235
250
    {
236
251
      safe_strncat (buf, sizeof (buf), " BODY=8BITMIME", 15);
325
340
static int smtp_helo (CONNECTION* conn)
326
341
{
327
342
  char buf[LONG_STRING];
 
343
  const char* fqdn;
328
344
 
329
345
  memset (Capabilities, 0, sizeof (Capabilities));
330
346
 
339
355
#endif
340
356
  }
341
357
 
342
 
  snprintf (buf, sizeof (buf), "%s %s\r\n", Esmtp ? "EHLO" : "HELO", Fqdn);
 
358
  if(!(fqdn = mutt_fqdn (0)))
 
359
    fqdn = NONULL (Hostname);
 
360
 
 
361
  snprintf (buf, sizeof (buf), "%s %s\r\n", Esmtp ? "EHLO" : "HELO", fqdn);
343
362
  /* XXX there should probably be a wrapper in mutt_socket.c that
344
363
    * repeatedly calls conn->write until all data is sent.  This
345
364
    * currently doesn't check for a short write.
435
454
 
436
455
      dprint (2, (debugfile, "smtp_authenticate: Trying method %s\n", method));
437
456
 
438
 
      if ((r = smtp_auth_sasl (conn, method)) != SMTP_AUTH_UNAVAIL)
 
457
      r = smtp_auth_sasl (conn, method);
 
458
      
 
459
      if (r == SMTP_AUTH_FAIL && delim)
 
460
      {
 
461
        mutt_error (_("%s authentication failed, trying next method"), method);
 
462
        mutt_sleep (1);
 
463
      }
 
464
      else if (r != SMTP_AUTH_UNAVAIL)
439
465
        break;
440
466
    }
441
467
 
447
473
  if (r != SMTP_AUTH_SUCCESS)
448
474
    mutt_account_unsetpass (&conn->account);
449
475
 
450
 
  if (r == SMTP_AUTH_UNAVAIL)
 
476
  if (r == SMTP_AUTH_FAIL)
 
477
  {
 
478
    mutt_error (_("SASL authentication failed"));
 
479
    mutt_sleep (1);
 
480
  }
 
481
  else if (r == SMTP_AUTH_UNAVAIL)
451
482
  {
452
483
    mutt_error (_("No authenticators available"));
453
484
    mutt_sleep (1);
484
515
    return SMTP_AUTH_UNAVAIL;
485
516
  }
486
517
 
487
 
  mutt_message (_("Authenticating (%s)..."), mech);
 
518
  if (!option(OPTNOCURSES))
 
519
    mutt_message (_("Authenticating (%s)..."), mech);
488
520
 
489
521
  snprintf (buf, sizeof (buf), "AUTH %s", mech);
490
522
  if (len)
539
571
    mutt_sasl_setup_conn (conn, saslconn);
540
572
    return SMTP_AUTH_SUCCESS;
541
573
  }
542
 
  else if (SmtpAuthenticators && *SmtpAuthenticators)
543
 
  {
544
 
    /* if we're given a mech list to attempt, failure means try the next */
545
 
    dprint (2, (debugfile, "smtp_auth_sasl: %s failed\n", mech));
546
 
    sasl_dispose (&saslconn);
547
 
    return SMTP_AUTH_UNAVAIL;
548
 
  }
549
574
 
550
575
fail:
551
 
  mutt_error (_("SASL authentication failed"));
552
 
  mutt_sleep (1);
553
576
  sasl_dispose (&saslconn);
554
577
  return SMTP_AUTH_FAIL;
555
578
}