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

« back to all changes in this revision

Viewing changes to mbox.c

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-06-17 17:17:28 UTC
  • mfrom: (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20090617171728-61dkl7w5fgn7ybdq
Tags: upstream-1.5.20
Import upstream version 1.5.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
208
208
        hdr->env->return_path = rfc822_parse_adrlist (hdr->env->return_path, return_path);
209
209
 
210
210
      if (!hdr->env->from)
211
 
        hdr->env->from = rfc822_cpy_adr (hdr->env->return_path);
 
211
        hdr->env->from = rfc822_cpy_adr (hdr->env->return_path, 0);
212
212
 
213
213
      ctx->msgcount++;
214
214
    }
383
383
        curhdr->env->return_path = rfc822_parse_adrlist (curhdr->env->return_path, return_path);
384
384
 
385
385
      if (!curhdr->env->from)
386
 
        curhdr->env->from = rfc822_cpy_adr (curhdr->env->return_path);
 
386
        curhdr->env->from = rfc822_cpy_adr (curhdr->env->return_path, 0);
387
387
 
388
388
      lines = 0;
389
389
    }
679
679
  return (-1);
680
680
}
681
681
 
 
682
/* if mailbox has at least 1 new message, sets mtime > atime of mailbox
 
683
 * so buffy check reports new mail */
 
684
static void reset_atime (CONTEXT *ctx)
 
685
{
 
686
  struct utimbuf utimebuf;
 
687
  int i;
 
688
  time_t now = time (NULL);
 
689
 
 
690
  for (i = 0; i < ctx->msgcount; i++)
 
691
  {
 
692
    if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
 
693
    {
 
694
      utimebuf.actime = now - 1;
 
695
      utimebuf.modtime = now;
 
696
      utime (ctx->path, &utimebuf);
 
697
      return;
 
698
    }
 
699
  }
 
700
}
 
701
 
682
702
/* return values:
683
703
 *      0       success
684
704
 *      -1      failure
692
712
  int need_sort = 0; /* flag to resort mailbox if new mail arrives */
693
713
  int first = -1;       /* first message to be written */
694
714
  LOFF_T offset;        /* location in mailbox to write changed messages */
695
 
  struct stat statbuf;
696
 
  struct utimbuf utimebuf;
697
715
  struct m_update_t *newOffset = NULL;
698
716
  struct m_update_t *oldOffset = NULL;
699
717
  FILE *fp = NULL;
877
895
  if (fclose (fp) != 0)
878
896
  {
879
897
    fp = NULL;
880
 
    dprint(1, (debugfile, "mbox_sync_mailbox: fclose() returned non-zero.\n"));
 
898
    dprint(1, (debugfile, "mbox_sync_mailbox: safe_fclose (&) returned non-zero.\n"));
881
899
    unlink (tempfile);
882
900
    mutt_perror (tempfile);
883
901
    mutt_sleep (5);
885
903
  }
886
904
  fp = NULL;
887
905
 
888
 
  /* Save the state of this folder. */
889
 
  if (stat (ctx->path, &statbuf) == -1)
890
 
  {
891
 
    mutt_perror (ctx->path);
892
 
    mutt_sleep (5);
893
 
    unlink (tempfile);
894
 
    goto bail;
895
 
  }
896
 
 
897
906
  if ((fp = fopen (tempfile, "r")) == NULL)
898
907
  {
899
908
    mutt_unblock_signals ();
926
935
      /* copy the temp mailbox back into place starting at the first
927
936
       * change/deleted message
928
937
       */
929
 
      mutt_message _("Committing changes...");
 
938
      if (!ctx->quiet)
 
939
        mutt_message _("Committing changes...");
930
940
      i = mutt_copy_stream (fp, ctx->fp);
931
941
 
932
942
      if (ferror (ctx->fp))
939
949
    }
940
950
  }
941
951
 
942
 
  fclose (fp);
 
952
  safe_fclose (&fp);
943
953
  fp = NULL;
944
954
  mbox_unlock_mailbox (ctx);
945
955
 
962
972
    return (-1);
963
973
  }
964
974
 
965
 
  /* Restore the previous access/modification times */
966
 
  utimebuf.actime = statbuf.st_atime;
967
 
  utimebuf.modtime = statbuf.st_mtime;
968
 
  utime (ctx->path, &utimebuf);
969
 
 
970
975
  /* reopen the mailbox in read-only mode */
971
976
  if ((ctx->fp = fopen (ctx->path, "r")) == NULL)
972
977
  {
993
998
  unlink (tempfile); /* remove partial copy of the mailbox */
994
999
  mutt_unblock_signals ();
995
1000
 
 
1001
  /* if mailbox has new mail, mangle atime+mtime to make buffy check
 
1002
   * report new mail for it */
 
1003
  if (!option (OPTCHECKMBOXSIZE))
 
1004
    reset_atime (ctx);
 
1005
 
996
1006
  return (0); /* signal success */
997
1007
 
998
1008
bail:  /* Come here in case of disaster */
1056
1066
  /* silent operations */
1057
1067
  ctx->quiet = 1;
1058
1068
  
1059
 
  mutt_message _("Reopening mailbox...");
 
1069
  if (!ctx->quiet)
 
1070
    mutt_message _("Reopening mailbox...");
1060
1071
  
1061
1072
  /* our heuristics require the old mailbox to be unsorted */
1062
1073
  if (Sort != SORT_ORDER)
1109
1120
  {
1110
1121
    case M_MBOX:
1111
1122
    case M_MMDF:
1112
 
      if (fseek (ctx->fp, 0, SEEK_SET) != 0)
1113
 
      {
1114
 
        dprint (1, (debugfile, "mutt_reopen_mailbox: fseek() failed\n"));
1115
 
        rc = -1;
1116
 
      } 
1117
 
      else 
1118
 
      {
1119
 
        cmp_headers = mbox_strict_cmp_headers;
1120
 
        rc = ((ctx->magic == M_MBOX) ? mbox_parse_mailbox
1121
 
                                     : mmdf_parse_mailbox) (ctx);
1122
 
      }
 
1123
      cmp_headers = mbox_strict_cmp_headers;
 
1124
      safe_fclose (&ctx->fp);
 
1125
      if (!(ctx->fp = safe_fopen (ctx->path, "r")))
 
1126
        rc = -1;
 
1127
      else
 
1128
        rc = ((ctx->magic == M_MBOX) ? mbox_parse_mailbox
 
1129
                                       : mmdf_parse_mailbox) (ctx);
1123
1130
      break;
1124
1131
 
1125
1132
    default: