Show
Ignore:
Timestamp:
1999-04-12 12:13:29 (10 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Clean-up, from Vikas.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • compose.c

    r996 r1002  
    445445  CONTEXT *ctx = NULL, *this = NULL; 
    446446  /* Sort, SortAux could be changed in mutt_index_menu() */ 
    447   int oldSort = Sort, oldSortAux = SortAux; 
     447  int oldSort, oldSortAux; 
    448448  struct stat st; 
    449   char **files; 
    450   int numfiles; 
    451449 
    452450  idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1); 
     
    594592 
    595593      case OP_COMPOSE_ATTACH_FILE: 
    596       case OP_COMPOSE_ATTACH_MESSAGE: 
    597  
    598         fname[0] = 0; 
    599         { 
    600           char* prompt; 
    601           int flag; 
    602  
    603           if (op == OP_COMPOSE_ATTACH_FILE) 
    604           { 
    605             prompt = _("Attach file"); 
    606             flag = 0; 
    607             numfiles = 0; 
    608             files = NULL; 
    609             if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag, 1, &files, &numfiles) == -1) 
    610               break; 
    611           } 
    612           else 
    613           { 
    614             prompt = _("Open mailbox to attach message from"); 
    615             if (Context) 
    616             { 
    617               strfcpy (fname, NONULL (Context->path), sizeof (fname)); 
    618               mutt_pretty_mailbox (fname); 
    619             } 
    620             flag = 1; 
    621             if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag) == -1 || !fname[0]) 
    622               break; 
    623             mutt_expand_path (fname, sizeof (fname)); 
    624             /* check to make sure the file exists and is readable */ 
    625             if (access (fname, R_OK) == -1) 
    626             { 
    627               mutt_perror (fname); 
    628               break; 
    629             } 
    630           } 
    631         } 
    632  
    633         if (op == OP_COMPOSE_ATTACH_MESSAGE) 
    634         { 
    635           menu->redraw = REDRAW_FULL; 
    636  
    637           ctx = mx_open_mailbox (fname, M_READONLY, NULL); 
    638           if (ctx == NULL) 
    639           { 
    640             mutt_perror (fname); 
     594        { 
     595          char *prompt, **files; 
     596          int error, numfiles; 
     597 
     598          fname[0] = 0; 
     599          prompt = _("Attach file"); 
     600          numfiles = 0; 
     601          files = NULL; 
     602 
     603          if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 0, 1, &files, &numfiles) == -1) 
    641604            break; 
    642           } 
    643  
    644           if (!ctx->msgcount) 
    645           { 
    646             mx_close_mailbox (ctx); 
    647             safe_free ((void **) &ctx); 
    648             mutt_error _("No messages in that folder."); 
    649             break; 
    650           } 
    651            
    652           this = Context; /* remember current folder */ 
    653           Context = ctx; 
    654           set_option(OPTATTACHMSG); 
    655           mutt_message _("Tag the messages you want to attach!"); 
    656           close = mutt_index_menu (); 
    657           unset_option(OPTATTACHMSG); 
    658  
    659           if (!Context) 
    660           { 
    661             /* go back to the folder we started from */ 
    662             Context = this; 
    663             /* Restore old $sort and $sort_aux */ 
    664             Sort = oldSort; 
    665             SortAux = oldSortAux; 
    666             menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; 
    667             break; 
    668           } 
    669         } 
    670  
    671         { 
    672           int numtag = 0; 
    673  
    674           if (op == OP_COMPOSE_ATTACH_MESSAGE) 
    675             numtag = Context->tagged; 
    676           else 
    677             numtag = numfiles; 
    678           if (idxlen + numtag >= idxmax) 
    679           { 
    680             safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numtag)); 
     605 
     606          if (idxlen + numfiles >= idxmax) 
     607          { 
     608            safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numfiles)); 
    681609            menu->data = idx; 
    682610          } 
    683         } 
    684  
    685         if (op == OP_COMPOSE_ATTACH_FILE) 
    686         { 
    687           int error = 0; 
    688           mutt_message _("Attaching selected files..."); 
     611 
     612          error = 0; 
     613          if (numfiles > 1) 
     614            mutt_message _("Attaching selected files..."); 
    689615          for (i = 0; i < numfiles; i++) 
    690616          { 
     
    700626              safe_free ((void **) &idx[idxlen]); 
    701627            } 
    702             FREE (&this); 
    703           } 
     628          } 
     629           
    704630          FREE (&files); 
    705           if (!error) 
    706             mutt_clear_error (); 
     631          if (!error) mutt_clear_error (); 
     632 
    707633          menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; 
    708         } 
    709         else 
    710         { 
     634        } 
     635        break; 
     636 
     637      case OP_COMPOSE_ATTACH_MESSAGE: 
     638        { 
     639          char *prompt; 
    711640          HEADER *h; 
     641 
     642          fname[0] = 0; 
     643          prompt = _("Open mailbox to attach message from"); 
     644 
     645          if (Context) 
     646          { 
     647            strfcpy (fname, NONULL (Context->path), sizeof (fname)); 
     648            mutt_pretty_mailbox (fname); 
     649          } 
     650 
     651          if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, 1) == -1 || !fname[0]) 
     652            break; 
     653 
     654          mutt_expand_path (fname, sizeof (fname)); 
     655          /* check to make sure the file exists and is readable */ 
     656          if (access (fname, R_OK) == -1) 
     657          { 
     658            mutt_perror (fname); 
     659            break; 
     660          } 
     661 
     662          menu->redraw = REDRAW_FULL; 
     663 
     664          ctx = mx_open_mailbox (fname, M_READONLY, NULL); 
     665          if (ctx == NULL) 
     666          { 
     667            mutt_perror (fname); 
     668            break; 
     669          } 
     670 
     671          if (!ctx->msgcount) 
     672          { 
     673            mx_close_mailbox (ctx); 
     674            safe_free ((void **) &ctx); 
     675            mutt_error _("No messages in that folder."); 
     676            break; 
     677          } 
     678 
     679          this = Context; /* remember current folder and sort methods*/ 
     680          oldSort = Sort; oldSortAux = SortAux; 
     681           
     682          Context = ctx; 
     683          set_option(OPTATTACHMSG); 
     684          mutt_message _("Tag the messages you want to attach!"); 
     685          close = mutt_index_menu (); 
     686          unset_option(OPTATTACHMSG); 
     687 
     688          if (!Context) 
     689          { 
     690            /* go back to the folder we started from */ 
     691            Context = this; 
     692            /* Restore old $sort and $sort_aux */ 
     693            Sort = oldSort; 
     694            SortAux = oldSortAux; 
     695            menu->redraw |= REDRAW_INDEX | REDRAW_STATUS; 
     696            break; 
     697          } 
     698 
     699          if (idxlen + Context->tagged >= idxmax) 
     700          { 
     701            safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5 + Context->tagged)); 
     702            menu->data = idx; 
     703          } 
     704 
    712705          for (i = 0; i < Context->msgcount; i++) 
    713706          { 
     
    740733          SortAux = oldSortAux; 
    741734        } 
    742  
    743735        break; 
    744736