~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): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-17 17:17:28 UTC
  • mfrom: (1.1.11 upstream) (16.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090617171728-lj10l5x2m2vg6cag
Tags: 1.5.20-1ubuntu1
* Merge from debian unstable (LP: #388515)
* Build-depend on elinks-lite
  + elinks-lite doesn't provide links anymore.
  + elinks-lite is now in main, and pulls less dependencies than the
    full-fledged elinks.
* debian/control: Recommend default-mta instead of exim4. (LP: #386308)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
 
48
48
#define smtp_err_read -2
49
49
#define smtp_err_write -3
 
50
#define smtp_err_code -4
50
51
 
51
52
#define SMTP_PORT 25
52
53
#define SMTPS_PORT 465
76
77
static char* AuthMechs = NULL;
77
78
static unsigned char Capabilities[(CAPMAX + 7)/ 8];
78
79
 
 
80
static int smtp_code (char *buf, size_t len, int *n)
 
81
{
 
82
  char code[4];
 
83
 
 
84
  if (len < 4)
 
85
    return -1;
 
86
  code[0] = buf[0];
 
87
  code[1] = buf[1];
 
88
  code[2] = buf[2];
 
89
  code[3] = 0;
 
90
  if (mutt_atoi (code, n) < 0)
 
91
    return -1;
 
92
  return 0;
 
93
}
 
94
 
79
95
/* Reads a command response from the SMTP server.
80
96
 * Returns:
81
97
 * 0    on success (2xx code) or continue (354 code)
107
123
    else if (!ascii_strncasecmp ("STARTTLS", buf + 4, 8))
108
124
      mutt_bit_set (Capabilities, STARTTLS);
109
125
 
110
 
    n = atoi (buf);
 
126
    if (smtp_code (buf, n, &n) < 0)
 
127
      return smtp_err_code;
 
128
 
111
129
  } while (buf[3] == '-');
112
130
 
113
131
  if (smtp_success (n) || n == smtp_continue)
125
143
 
126
144
  while (a)
127
145
  {
 
146
    /* weed out group mailboxes, since those are for display only */
 
147
    if (!a->mailbox || a->group)
 
148
    {
 
149
      a = a->next;
 
150
      continue;
 
151
    }
128
152
    if (mutt_bit_isset (Capabilities, DSN) && DsnNotify)
129
153
      snprintf (buf, sizeof (buf), "RCPT TO:<%s> NOTIFY=%s\r\n",
130
154
                a->mailbox, DsnNotify);
147
171
  FILE *fp = 0;
148
172
  progress_t progress;
149
173
  struct stat st;
150
 
  int r;
 
174
  int r, term = 0;
151
175
  size_t buflen;
152
176
 
153
177
  fp = fopen (msgfile, "r");
164
188
  snprintf (buf, sizeof (buf), "DATA\r\n");
165
189
  if (mutt_socket_write (conn, buf) == -1)
166
190
  {
167
 
    fclose (fp);
 
191
    safe_fclose (&fp);
168
192
    return smtp_err_write;
169
193
  }
170
194
  if ((r = smtp_get_resp (conn)))
171
195
  {
172
 
    fclose (fp);
 
196
    safe_fclose (&fp);
173
197
    return r;
174
198
  }
175
199
 
176
200
  while (fgets (buf, sizeof (buf) - 1, fp))
177
201
  {
178
202
    buflen = mutt_strlen (buf);
 
203
    term = buf[buflen-1] == '\n';
179
204
    if (buflen && buf[buflen-1] == '\n'
180
205
        && (buflen == 1 || buf[buflen - 2] != '\r'))
181
206
      snprintf (buf + buflen - 1, sizeof (buf) - buflen + 1, "\r\n");
183
208
    {
184
209
      if (mutt_socket_write_d (conn, ".", -1, M_SOCK_LOG_FULL) == -1)
185
210
      {
186
 
        fclose (fp);
 
211
        safe_fclose (&fp);
187
212
        return smtp_err_write;
188
213
      }
189
214
    }
190
215
    if (mutt_socket_write_d (conn, buf, -1, M_SOCK_LOG_FULL) == -1)
191
216
    {
192
 
      fclose (fp);
 
217
      safe_fclose (&fp);
193
218
      return smtp_err_write;
194
219
    }
195
 
 
196
220
    mutt_progress_update (&progress, ftell (fp), -1);
197
221
  }
198
 
  fclose (fp);
 
222
  if (!term && buflen &&
 
223
      mutt_socket_write_d (conn, "\r\n", -1, M_SOCK_LOG_FULL) == -1)
 
224
  {
 
225
    safe_fclose (&fp);
 
226
    return smtp_err_write;
 
227
  }
 
228
  safe_fclose (&fp);
199
229
 
200
230
  /* terminate the message body */
201
231
  if (mutt_socket_write (conn, ".\r\n") == -1)
284
314
    mutt_error (_("SMTP session failed: read error"));
285
315
  else if (ret == smtp_err_write)
286
316
    mutt_error (_("SMTP session failed: write error"));
 
317
  else if (ret == smtp_err_code)
 
318
    mutt_error (_("Invalid server response"));
287
319
 
288
320
  return ret;
289
321
}
422
454
    }
423
455
 
424
456
#ifdef USE_SASL
 
457
    if (!(conn->account.flags & M_ACCT_PASS) && option (OPTNOCURSES))
 
458
    {
 
459
      mutt_error (_("Interactive SMTP authentication not supported"));
 
460
      mutt_sleep (1);
 
461
      return -1;
 
462
    }
425
463
    return smtp_auth (conn);
426
464
#else
427
465
    mutt_error (_("SMTP authentication requires SASL"));
534
572
  do {
535
573
    if (mutt_socket_write (conn, buf) < 0)
536
574
      goto fail;
537
 
    if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
538
 
      goto fail;
539
 
    rc = atoi(buf);
 
575
    if ((rc = mutt_socket_readln (buf, sizeof (buf), conn)) < 0)
 
576
      goto fail;
 
577
    if (smtp_code (buf, rc, &rc) < 0)
 
578
      goto fail;
540
579
 
541
580
    if (rc != smtp_ready)
542
581
      break;