/* returns 1 if OK to proceed, 0 to abort */ int mutt_save_confirm (const char *s, struct stat *st) { char tmp[_POSIX_PATH_MAX]; int ret = 1; int magic = 0; magic = mx_get_magic (s); if (stat (s, st) != -1) { if (magic == -1) { mutt_error (_("%s is not a mailbox!"), s); return 0; } if (option (OPTCONFIRMAPPEND)) { snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s); if (mutt_yesorno (tmp, 1) < 1) ret = 0; } } else { #ifdef USE_IMAP if (magic != M_IMAP) #endif /* execute the block unconditionally if we don't use imap */ { st->st_mtime = 0; st->st_atime = 0; if (errno == ENOENT) { if (option (OPTCONFIRMCREATE)) { snprintf (tmp, sizeof (tmp), _("Create %s?"), s); if (mutt_yesorno (tmp, 1) < 1) ret = 0; } } else { mutt_perror (s); return 0; } } } CLEARLINE (LINES-1); return (ret); }
/* imap_pretty_mailbox: called by mutt_pretty_mailbox to make IMAP paths * look nice. */ void imap_pretty_mailbox (char *path) { IMAP_MBOX home, target; ciss_url_t url; char *delim; int tlen; int hlen = 0; char home_match = 0; if (imap_parse_path (path, &target) < 0) return; tlen = str_len (target.mbox); /* check whether we can do '=' substitution */ if (mx_get_magic (Maildir) == M_IMAP && !imap_parse_path (Maildir, &home)) { hlen = str_len (home.mbox); if (tlen && mutt_account_match (&home.account, &target.account) && !str_ncmp (home.mbox, target.mbox, hlen)) { if (!hlen) home_match = 1; else for (delim = ImapDelimChars; *delim != '\0'; delim++) if (target.mbox[hlen] == *delim) home_match = 1; } mem_free (&home.mbox); } /* do the '=' substitution */ if (home_match) { *path++ = '='; /* copy remaining path, skipping delimiter */ if (!hlen) hlen = -1; memcpy (path, target.mbox + hlen + 1, tlen - hlen - 1); path[tlen - hlen - 1] = '\0'; } else { mutt_account_tourl (&target.account, &url); url.path = target.mbox; /* FIXME: That hard-coded constant is bogus. But we need the actual * size of the buffer from mutt_pretty_mailbox. And these pretty * operations usually shrink the result. Still... */ url_ciss_tostring (&url, path, 1024, 0); } mem_free (&target.mbox); }
int mutt_can_append_compressed (const char *path) { int magic; if (is_new (path)) return (find_compress_hook (M_CLOSEHOOK, path) ? 1 : 0); magic = mx_get_magic (path); if (magic != 0 && magic != M_COMPRESSED) return 0; return (find_compress_hook (M_APPENDHOOK, path) || (find_compress_hook (M_OPENHOOK, path) && find_compress_hook (M_CLOSEHOOK, path))) ? 1 : 0; }
int mutt_open_read_compressed (CONTEXT * ctx) { char *cmd; FILE *fp; int rc; COMPRESS_INFO *ci = set_compress_info (ctx); if (!ci->open) { ctx->magic = 0; mem_free (ctx->compressinfo); return (-1); } if (!ci->close || access (ctx->path, W_OK) != 0) ctx->readonly = 1; set_path (ctx); store_size (ctx); if (!ctx->quiet) mutt_message (_("Decompressing %s..."), ctx->realpath); cmd = get_compression_cmd (ci->open, ctx); if (cmd == NULL) return (-1); debug_print (2, ("DecompressCmd: '%s'\n", cmd)); if ((fp = fopen (ctx->realpath, "r")) == NULL) { mutt_perror (ctx->realpath); mem_free (&cmd); return (-1); } mutt_block_signals (); if (mbox_lock_compressed (ctx, fp, 0, 1) == -1) { fclose (fp); mutt_unblock_signals (); mutt_error _("Unable to lock mailbox!"); mem_free (&cmd); return (-1); } endwin (); fflush (stdout); sprintf (echo_cmd, _("echo Decompressing %s..."), ctx->realpath); mutt_system (echo_cmd); rc = mutt_system (cmd); mbox_unlock_compressed (ctx, fp); mutt_unblock_signals (); fclose (fp); if (rc) { mutt_any_key_to_continue (NULL); ctx->magic = 0; mem_free (ctx->compressinfo); mutt_error (_("Error executing: %s : unable to open the mailbox!\n"), cmd); } mem_free (&cmd); if (rc) return (-1); if (mutt_check_mailbox_compressed (ctx)) return (-1); ctx->magic = mx_get_magic (ctx->path); return (0); }
/* returns 0 if OK to proceed, -1 to abort, 1 to retry */ int mutt_save_confirm (const char *s, struct stat *st) { char tmp[_POSIX_PATH_MAX]; int ret = 0; int rc; int magic = 0; magic = mx_get_magic (s); #ifdef USE_POP if (magic == M_POP) { mutt_error _("Can't save message to POP mailbox."); return 1; } #endif #ifdef USE_NNTP if (magic == M_NNTP) { mutt_error _("Can't save message to newsserver."); return 0; } #endif if (magic > 0 && !mx_access (s, W_OK)) { if (option (OPTCONFIRMAPPEND) && (!TrashPath || (str_cmp (s, TrashPath) != 0))) { /* if we're appending to the trash, there's no point in asking */ snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s); if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO) ret = 1; else if (rc == -1) ret = -1; } } if (stat (s, st) != -1) { if (magic == -1) { mutt_error (_("%s is not a mailbox!"), s); return 1; } } else { #ifdef USE_IMAP if (magic != M_IMAP) #endif /* execute the block unconditionally if we don't use imap */ { st->st_mtime = 0; st->st_atime = 0; if (errno == ENOENT) { if (option (OPTCONFIRMCREATE)) { snprintf (tmp, sizeof (tmp), _("Create %s?"), s); if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO) ret = 1; else if (rc == -1) ret = -1; } } else { mutt_perror (s); return 1; } } } CLEARLINE (LINES - 1); return (ret); }