int alias_tag (MUTTMENU *menu, int n)
{
- return (((ALIAS **) menu->data)[n]->tagged = !((ALIAS **) menu->data)[n]->tagged);
+ return ((((ALIAS **) menu->data)[n]->tagged = !((ALIAS **) menu->data)[n]->tagged) ? 1 : -1);
}
static int alias_SortAlias (const void *a, const void *b)
off_t size;
char *name;
char *desc;
+ short tagged;
};
struct browser_state
state->entrylen = 0;
state->entrymax = 256;
state->entry = (struct folder_file *) safe_malloc (sizeof (struct folder_file) * state->entrymax);
+ memset (state->entry, 0, sizeof (struct folder_file) * state->entrymax);
if (menu)
menu->data = state->entry;
}
void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
{
- snprintf (s, slen, "%2d %s", num + 1, ((struct folder_file *) menu->data)[num].desc);
+ snprintf (s, slen, "%2d %c %s",
+ num + 1,
+ ((struct folder_file *) menu->data)[num].tagged ? '*' : ' ',
+ ((struct folder_file *) menu->data)[num].desc);
}
static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
menu->redraw = REDRAW_FULL;
}
-void mutt_select_file (char *f, size_t flen, int buffy)
+int file_tag (MUTTMENU *menu, int n)
+{
+ struct folder_file *ff = &(((struct folder_file *)menu->data)[n]);
+ if (S_ISDIR (ff->mode) || (S_ISLNK (ff->mode) && link_is_dir (ff->name)))
+ {
+ mutt_error _("Can't attach a directory!");
+ return 0;
+ }
+
+ return ((ff->tagged = !ff->tagged) ? 1 : -1);
+}
+
+void _mutt_select_file (char *f, size_t flen, int buffy,
+ int multiple, char ***files, int *numfiles)
{
char buf[_POSIX_PATH_MAX];
char prefix[_POSIX_PATH_MAX] = "";
menu->search = select_file_search;
menu->title = title;
menu->data = state.entry;
+ if (multiple)
+ menu->tag = file_tag;
menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_FOLDER, FolderHelp);
case OP_EXIT:
+ if (multiple)
+ {
+ char **tfiles;
+ int i, j;
+
+ if (menu->tagged)
+ {
+ *numfiles = menu->tagged;
+ tfiles = safe_malloc (*numfiles * sizeof (char *));
+ for (i = 0, j = 0; i < state.entrylen; i++)
+ {
+ struct folder_file ff = state.entry[i];
+ char full[_POSIX_PATH_MAX];
+ if (ff.tagged)
+ {
+ snprintf (full, sizeof (full), "%s/%s", LastDir, ff.name);
+ mutt_expand_path (full, sizeof (full));
+ tfiles[j++] = safe_strdup (full);
+ }
+ }
+ *files = tfiles;
+ }
+ else if (f[0]) /* no tagged entries. return selected entry */
+ {
+ *numfiles = 1;
+ tfiles = safe_malloc (*numfiles * sizeof (char *));
+ mutt_expand_path (f, flen);
+ tfiles[0] = safe_strdup (f);
+ *files = tfiles;
+ }
+ }
+
destroy_state (&state);
mutt_menuDestroy (&menu);
return;
/* Sort, SortAux could be changed in mutt_index_menu() */
int oldSort = Sort, oldSortAux = SortAux;
struct stat st;
+ char **files;
+ int numfiles;
idx = mutt_gen_attach_list (msg->content, -1, idx, &idxlen, &idxmax, 0, 1);
{
prompt = _("Attach file");
flag = 0;
+ numfiles = 0;
+ files = NULL;
+ if (_mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag, 1, &files, &numfiles) == -1)
+ break;
}
else
{
mutt_pretty_mailbox (fname);
}
flag = 1;
+ if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag) == -1 || !fname[0])
+ break;
+ mutt_expand_path (fname, sizeof (fname));
+ /* check to make sure the file exists and is readable */
+ if (access (fname, R_OK) == -1)
+ {
+ mutt_perror (fname);
+ break;
+ }
}
-
- if (mutt_enter_fname (prompt, fname, sizeof (fname), &menu->redraw, flag) == -1)
- break;
- }
-
- if (!fname[0])
- continue;
- mutt_expand_path (fname, sizeof (fname));
-
- /* check to make sure the file exists and is readable */
- if (access (fname, R_OK) == -1)
- {
- mutt_perror (fname);
- break;
}
if (op == OP_COMPOSE_ATTACH_MESSAGE)
if (op == OP_COMPOSE_ATTACH_MESSAGE)
numtag = Context->tagged;
+ else
+ numtag = numfiles;
if (idxlen + numtag >= idxmax)
{
safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5 + numtag));
if (op == OP_COMPOSE_ATTACH_FILE)
{
- idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
- idx[idxlen]->content = mutt_make_file_attach (fname);
- if (idx[idxlen]->content != NULL)
- update_idx (menu, idx, idxlen++);
- else
+ int error = 0;
+ mutt_message _("Attaching selected files...");
+ for (i = 0; i < numfiles; i++)
{
- mutt_error _("Unable to attach!");
- safe_free ((void **) &idx[idxlen]);
+ char *att = files[i];
+ idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
+ idx[idxlen]->content = mutt_make_file_attach (att);
+ if (idx[idxlen]->content != NULL)
+ update_idx (menu, idx, idxlen++);
+ else
+ {
+ error = 1;
+ mutt_error (_("Unable to attach %s!"), att);
+ safe_free ((void **) &idx[idxlen]);
+ }
+ FREE (&this);
}
+ FREE (&files);
+ if (!error)
+ mutt_clear_error ();
menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
- break;
}
else
{
}
}
menu->redraw |= REDRAW_FULL;
+
+ if (close == OP_QUIT)
+ mx_close_mailbox (Context);
+ else
+ mx_fastclose_mailbox (Context);
+ safe_free ((void **) &Context);
+
+ /* go back to the folder we started from */
+ Context = this;
+ /* Restore old $sort and $sort_aux */
+ Sort = oldSort;
+ SortAux = oldSortAux;
}
- if (close == OP_QUIT)
- mx_close_mailbox (Context);
- else
- mx_fastclose_mailbox (Context);
- safe_free ((void **) &Context);
-
- /* go back to the folder we started from */
- Context = this;
- /* Restore old $sort and $sort_aux */
- Sort = oldSort;
- SortAux = oldSortAux;
break;
case OP_DELETE:
return (ch == ctrl ('G') ? err : ret);
}
-int mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete)
+int _mutt_get_field (/* const */ char *field, char *buf, size_t buflen, int complete, int multiple, char ***files, int *numfiles)
{
int ret;
int len = mutt_strlen (field); /* in case field==buffer */
CLEARLINE (LINES-1);
addstr (field);
mutt_refresh ();
- ret = mutt_enter_string ((unsigned char *) buf, buflen, LINES-1, len, complete);
+ ret = _mutt_enter_string ((unsigned char *) buf, buflen, LINES-1, len, complete, multiple, files, numfiles);
}
while (ret == 1);
CLEARLINE (LINES-1);
return rc;
}
-int mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy)
+int _mutt_enter_fname (const char *prompt, char *buf, size_t blen, int *redraw, int buffy, int multiple, char ***files, int *numfiles)
{
event_t ch;
{
mutt_refresh ();
buf[0] = 0;
- mutt_select_file (buf, blen, 0);
+ _mutt_select_file (buf, blen, 0, multiple, files, numfiles);
*redraw = REDRAW_FULL;
}
else
sprintf (pc, "%s: ", prompt);
mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
- if (mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR)
+ if (_mutt_get_field (pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files, numfiles)
!= 0)
buf[0] = 0;
MAYBE_REDRAW (*redraw);
* -1 if abort.
*
*/
-int mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
- int flags)
+int _mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x,
+ int flags, int multiple, char ***files, int *numfiles)
{
event_t event;
int curpos = 0; /* the location of the cursor */
/* see if the path has changed from the last time */
if (mutt_strcmp (tempbuf, (char *) buf) == 0)
{
- mutt_select_file ((char *) buf, buflen, 0);
+ _mutt_select_file ((char *) buf, buflen, 0, multiple, files, numfiles);
set_option (OPTNEEDREDRAW);
if (buf[0])
{
{
if (menu->max)
{
- if (menu->tag (menu, menu->current))
- menu->tagged++;
- else
- menu->tagged--;
- if (option (OPTRESOLVE) && menu->current < menu->max - 1)
+ short i = menu->tag (menu, menu->current);
+ menu->tagged += i;
+ if (i && option (OPTRESOLVE) && menu->current < menu->max - 1)
{
menu->current++;
menu->redraw = REDRAW_MOTION_RESYNCH;
void mutt_save_path (char *s, size_t l, ADDRESS *a);
void mutt_score_message (HEADER *);
void mutt_select_fcc (char *, size_t, HEADER *);
-void mutt_select_file (char *, size_t, int);
+#define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,0,NULL,NULL)
+void _mutt_select_file (char *, size_t, int, int, char ***, int *);
void mutt_send_hook (HEADER *);
void mutt_set_flag (CONTEXT *, HEADER *, int, int);
void mutt_set_followup_to (ENVELOPE *);
int mutt_display_message (HEADER *h);
int mutt_edit_attachment(BODY *);
int mutt_prepare_edit_message(CONTEXT *, HEADER *, HEADER *);
-int mutt_enter_fname (const char *, char *, size_t, int *, int);
-int mutt_enter_string (unsigned char *, size_t, int, int, int);
-int mutt_get_field (char *, char *, size_t, int);
+#define mutt_enter_fname(A,B,C,D,E) _mutt_enter_fname(A,B,C,D,E,0,NULL,NULL)
+int _mutt_enter_fname (const char *, char *, size_t, int *, int, int, char ***, int *);
+#define mutt_enter_string(A,B,C,D,E) _mutt_enter_string(A,B,C,D,E,0,NULL,NULL)
+int _mutt_enter_string (unsigned char *, size_t, int, int, int, int, char ***, int *);
+#define mutt_get_field(A,B,C,D) _mutt_get_field(A,B,C,D,0,NULL,NULL)
+int _mutt_get_field (char *, char *, size_t, int, int, char ***, int *);
int mutt_get_password (char *, char *, size_t);
int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **, char *, size_t);
int mutt_get_tmp_attachment (BODY *);
static int query_tag (MUTTMENU *menu, int n)
{
- return (((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged);
+ return ((((ENTRY *) menu->data)[n].tagged = !((ENTRY *) menu->data)[n].tagged) ? 1 : -1);
}
int mutt_query_complete (char *buf, size_t buflen)
int mutt_tag_attach (MUTTMENU *menu, int n)
{
- return (((ATTACHPTR **) menu->data)[n]->content->tagged = !((ATTACHPTR **) menu->data)[n]->content->tagged);
+ return ((((ATTACHPTR **) menu->data)[n]->content->tagged = !((ATTACHPTR **) menu->data)[n]->content->tagged) ? 1 : -1);
}
int mutt_is_message_type (int type, const char *subtype)