+2006-02-19 Josh Bressers <josh@bress.net>
+
+ * sbr/m_draft.c, sbr/utils.c, uip/folder.c, uip/inc.c,
+ uip/mhstoresbr.c, uip/popi.c, uip/refile.c: Add create_folder()
+ function, replacing duplicate code during folder creation.
+
2006-02-18 David Levine <levinedl@acm.org>
- * h/mime.h, h/mhparse.h, uip/mhbuildsbr.c, uip/mhfree.c,
- man/mhbuild.man, docs/TODO: added support for an optional
- Content-Disposition header in mhbuild (only). Its contents
- are supplied between {}, positioned after the optional [], in
- a mhbuild directive. If the contents do not contain a
- "filename=" parameter, and the directive has a filename, or
- something else that ends with "name=", then that will be used
- to add a "filename=" parameter to the header.
+ * h/mime.h, h/mhparse.h, uip/mhbuildsbr.c, uip/mhfree.c,
+ man/mhbuild.man, docs/TODO: added support for an optional
+ Content-Disposition header in mhbuild (only). Its contents
+ are supplied between {}, positioned after the optional [], in
+ a mhbuild directive. If the contents do not contain a
+ "filename=" parameter, and the directive has a filename, or
+ something else that ends with "name=", then that will be used
+ to add a "filename=" parameter to the header.
2006-02-12 David Levine <levinedl@acm.org>
chdir (m_maildir (""));
strncpy (buffer, m_maildir (folder), sizeof(buffer));
- if (stat (buffer, &st) == -1) {
- if (errno != ENOENT)
- adios (buffer, "error on folder");
- cp = concat ("Create folder \"", buffer, "\"? ", NULL);
- if (!getanswer (cp))
- done (0);
- free (cp);
- if (!makedir (buffer))
- adios (NULL, "unable to create folder %s", buffer);
- }
+
+ create_folder (buffer, 0, done);
if (chdir (buffer) == -1)
adios (buffer, "unable to change directory to");
#include <h/mh.h>
#include <h/utils.h>
#include <stdlib.h>
+#include <errno.h>
/*
* Safely call malloc
return cp;
}
+
+/*
+ * create_folder
+ * Check to see if a folder exists, if not, prompt the user to create
+ * it.
+ */
+void create_folder(char *folder, int autocreate, void (*done_callback)())
+{
+ struct stat st;
+ extern int errno;
+ char *cp;
+
+ if (stat (folder, &st) == -1) {
+ if (errno != ENOENT)
+ adios (folder, "error on folder");
+ if (autocreate == 0) {
+ /* ask before creating folder */
+ cp = concat ("Create folder \"", folder, "\"? ", NULL);
+ if (!getanswer (cp))
+ done_callback (1);
+ free (cp);
+ } else if (autocreate == -1) {
+ /* do not create, so exit */
+ done_callback (1);
+ }
+ if (!makedir (folder))
+ adios (NULL, "unable to create folder %s", folder);
+ }
+}
* Check if folder exists. If not, then see if
* we should create it, or just exit.
*/
- if (stat (strncpy (buf, m_maildir (folder), sizeof(buf)), &st) == -1) {
- if (errno != ENOENT)
- adios (buf, "error on folder");
- if (fcreat == 0) {
- /* ask before creating folder */
- cp = concat ("Create folder \"", buf, "\"? ", NULL);
- if (!getanswer (cp))
- done (1);
- free (cp);
- } else if (fcreat == -1) {
- /* do not create, so exit */
- done (1);
- }
- if (!makedir (buf))
- adios (NULL, "unable to create folder %s", buf);
- }
+ create_folder (m_maildir (folder), fcreat, done);
if (get_folder_info (folder, msg) && argfolder) {
/* update current folder */
if ((maildir_copy = strdup(maildir)) == (char *)0)
adios (maildir, "error allocating memory to copy maildir");
- if (stat (maildir, &st) == NOTOK) {
- if (errno != ENOENT)
- adios (maildir, "error on folder");
- cp = concat ("Create folder \"", maildir, "\"? ", NULL);
- if (noisy && !getanswer (cp))
- done (1);
- free (cp);
- if (!makedir (maildir))
- adios (NULL, "unable to create folder %s", maildir);
- }
+ if (noisy)
+ create_folder(maildir, 0, done);
+ else
+ done (1);
if (chdir (maildir) == NOTOK)
adios (maildir, "unable to change directory to");
static int ct_compar (CT *, CT *);
static int store_content (CT, CT);
static int output_content_file (CT, int);
-static int check_folder (char *);
static int output_content_folder (char *, char *);
static int parse_format_string (CT, char *, char *, int, char *);
static void get_storeproc (CT);
folder = getfolder (1);
/* Check if folder exists */
- if (check_folder (folder) == NOTOK)
- return NOTOK;
+ create_folder(folder, 0, exit);
/* Record the folder name */
ct->c_folder = add (folder, NULL);
/*
- * Check if folder exists, and create
- * if necessary.
- */
-
-static int
-check_folder (char *folder)
-{
- char *folderdir;
- struct stat st;
-
- /* expand path to the folder */
- folderdir = m_mailpath (folder);
-
- /* Check if folder exists */
- if (stat (folderdir, &st) == NOTOK) {
- int answer;
- char *ep;
-
- if (errno != ENOENT) {
- advise (folderdir, "error on folder");
- return NOTOK;
- }
-
- ep = concat ("Create folder \"", folderdir, "\"? ", NULL);
- answer = getanswer (ep);
- free (ep);
-
- if (!answer)
- return NOTOK;
-
- if (!makedir (folderdir)) {
- advise (NULL, "unable to create folder %s", folderdir);
- return NOTOK;
- }
- }
-
- return OK;
-}
-
-
-/*
* Add a file to a folder.
*
* Return the new message number of the file
folder = getfolder (0);
maildir = m_maildir (folder);
- if (stat (maildir, &st) == NOTOK) {
- if (errno != ENOENT)
- adios (maildir, "error on folder");
- cp = concat ("Create folder \"", maildir, "\"? ", NULL);
- if (noisy && !getanswer (cp))
- done (1);
- free (cp);
- if (!makedir (maildir))
- adios (NULL, "unable to create folder %s", maildir);
- }
+ create_folder(maildir, 0, done);
if (chdir (maildir) == NOTOK)
adios (maildir, "unable to change directory to");
chdir (m_maildir (""));
strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir));
- if (stat (nmaildir, &st) == NOTOK) {
- if (errno != ENOENT)
- adios (nmaildir, "error on folder");
- cp = concat ("Create folder \"", nmaildir, "\"? ", NULL);
- if (!getanswer (cp))
- done (1);
- free (cp);
- if (!makedir (nmaildir))
- adios (NULL, "unable to create folder %s", nmaildir);
- }
+ create_folder (nmaildir, 0, done);
if (chdir (nmaildir) == NOTOK)
adios (nmaildir, "unable to change directory to");