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

« back to all changes in this revision

Viewing changes to sendlib.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:
1520
1520
/* arbitrary number of elements to grow the array by */
1521
1521
#define REF_INC 16
1522
1522
 
1523
 
#define TrimRef 10
1524
 
 
1525
1523
/* need to write the list in reverse because they are stored in reverse order
1526
1524
 * when parsed to speed up threading
1527
1525
 */
1528
 
static void write_references (LIST *r, FILE *f)
 
1526
void mutt_write_references (LIST *r, FILE *f, int trim)
1529
1527
{
1530
1528
  LIST **ref = NULL;
1531
1529
  int refcnt = 0, refmax = 0;
1532
1530
 
1533
 
  for ( ; (TrimRef == 0 || refcnt < TrimRef) && r ; r = r->next)
 
1531
  for ( ; (trim == 0 || refcnt < trim) && r ; r = r->next)
1534
1532
  {
1535
1533
    if (refcnt == refmax)
1536
1534
      safe_realloc (&ref, (refmax += REF_INC) * sizeof (LIST *));
1804
1802
 
1805
1803
  /* save message id if the user has set it */
1806
1804
  if (env->message_id && !privacy)
1807
 
    mutt_write_one_header (fp, "Message-ID", env->message_id, NULL, 0);
 
1805
    fprintf (fp, "Message-ID: %s\n", env->message_id);
1808
1806
 
1809
1807
  if (env->reply_to)
1810
1808
  {
1825
1823
    if (env->references)
1826
1824
    {
1827
1825
      fputs ("References:", fp);
1828
 
      write_references (env->references, fp);
 
1826
      mutt_write_references (env->references, fp, 10);
1829
1827
      fputc('\n', fp);
1830
1828
    }
1831
1829
 
1837
1835
  if (env->in_reply_to)
1838
1836
  {
1839
1837
    fputs ("In-Reply-To:", fp);
1840
 
    write_references (env->in_reply_to, fp);
 
1838
    mutt_write_references (env->in_reply_to, fp, 1);
1841
1839
    fputc ('\n', fp);
1842
1840
  }
1843
1841
  
2252
2250
  return (i);
2253
2251
}
2254
2252
 
2255
 
/* appends string 'b' to string 'a', and returns the pointer to the new
2256
 
   string. */
2257
 
char *mutt_append_string (char *a, const char *b)
2258
 
{
2259
 
  size_t la = mutt_strlen (a);
2260
 
  safe_realloc (&a, la + mutt_strlen (b) + 1);
2261
 
  strcpy (a + la, b);   /* __STRCPY_CHECKED__ */
2262
 
  return (a);
2263
 
}
2264
 
 
2265
 
/* returns 1 if char `c' needs to be quoted to protect from shell
2266
 
   interpretation when executing commands in a subshell */
2267
 
#define INVALID_CHAR(c) (!isalnum ((unsigned char)c) && !strchr ("@.+-_,:", c))
2268
 
 
2269
 
/* returns 1 if string `s' contains characters which could cause problems
2270
 
   when used on a command line to execute a command */
2271
 
int mutt_needs_quote (const char *s)
2272
 
{
2273
 
  while (*s)
2274
 
  {
2275
 
    if (INVALID_CHAR (*s))
2276
 
      return 1;
2277
 
    s++;
2278
 
  }
2279
 
  return 0;
2280
 
}
2281
 
 
2282
 
/* Quote a string to prevent shell escapes when this string is used on the
2283
 
   command line to send mail. */
2284
 
char *mutt_quote_string (const char *s)
2285
 
{
2286
 
  char *r, *pr;
2287
 
  size_t rlen;
2288
 
 
2289
 
  rlen = mutt_strlen (s) + 3;
2290
 
  pr = r = (char *) safe_malloc (rlen);
2291
 
  *pr++ = '"';
2292
 
  while (*s)
2293
 
  {
2294
 
    if (INVALID_CHAR (*s))
2295
 
    {
2296
 
      size_t o = pr - r;
2297
 
      safe_realloc (&r, ++rlen);
2298
 
      pr = r + o;
2299
 
      *pr++ = '\\';
2300
 
    }
2301
 
    *pr++ = *s++;
2302
 
  }
2303
 
  *pr++ = '"';
2304
 
  *pr = 0;
2305
 
  return (r);
2306
 
}
2307
 
 
2308
2253
/* For postponing (!final) do the necessary encodings only */
2309
2254
void mutt_prepare_envelope (ENVELOPE *env, int final)
2310
2255
{
2397
2342
  if ((f = safe_fopen (tempfile, "w")) != NULL)
2398
2343
  {
2399
2344
    int ch_flags = CH_XMIT | CH_NONEWLINE | CH_NOQFROM;
 
2345
    char* msgid_str;
2400
2346
    
2401
2347
    if (!option (OPTBOUNCEDELIVERED))
2402
2348
      ch_flags |= CH_WEED_DELIVERED;
2404
2350
    fseeko (fp, h->offset, 0);
2405
2351
    fprintf (f, "Resent-From: %s", resent_from);
2406
2352
    fprintf (f, "\nResent-%s", mutt_make_date (date, sizeof(date)));
2407
 
    fprintf (f, "Resent-Message-ID: %s\n", mutt_gen_msgid());
 
2353
    msgid_str = mutt_gen_msgid();
 
2354
    fprintf (f, "Resent-Message-ID: %s\n", msgid_str);
2408
2355
    fputs ("Resent-To: ", f);
2409
2356
    mutt_write_address_list (to, f, 11, 0);
2410
2357
    mutt_copy_header (fp, h, f, ch_flags, NULL);
2411
2358
    fputc ('\n', f);
2412
2359
    mutt_copy_bytes (fp, f, h->content->length);
2413
 
    fclose (f);
 
2360
    safe_fclose (&f);
 
2361
    FREE (&msgid_str);
2414
2362
 
2415
2363
#if USE_SMTP
2416
2364
    if (SmtpUrl)
2668
2616
    rewind (tempfp);
2669
2617
    while (fgets (sasha, sizeof (sasha), tempfp) != NULL)
2670
2618
      lines++;
2671
 
    fprintf (msg->fp, "Content-Length: " OFF_T_FMT "\n", (LOFF_T) ftell (tempfp));
 
2619
    fprintf (msg->fp, "Content-Length: " OFF_T_FMT "\n", (LOFF_T) ftello (tempfp));
2672
2620
    fprintf (msg->fp, "Lines: %d\n\n", lines);
2673
2621
 
2674
2622
    /* copy the body and clean up */