send: Convert system() to execprog() ... second half
authormarkus schnalke <meillo@marmaro.de>
Wed, 14 Jan 2015 21:24:34 +0000 (22:24 +0100)
committermarkus schnalke <meillo@marmaro.de>
Wed, 14 Jan 2015 21:24:34 +0000 (22:24 +0100)
Now only uip/spost.c has one left.

uip/send.c

index 3c2db0e..7e80bc4 100644 (file)
@@ -237,7 +237,7 @@ main(int argc, char **argv)
 static int
 sendsbr(char **vec, int vecp, char *drft, struct stat *st)
 {
-       int status;
+       int status, dupfd;
        char buffer[BUFSIZ];
        char *original_draft;
 
@@ -295,12 +295,16 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st)
                status = sendaux(vec, vecp, drft, st) ? NOTOK : OK;
                if (status == OK) {
                        /* move original draft to +trash folder */
-                       snprintf(buffer, sizeof buffer,
-                                       "</dev/null refile -file %s +trash",
-                                       original_draft);
-                       if (system(buffer) != 0) {
+                       /* temporary close stdin, for refile not to ask */
+                       dupfd = dup(0);
+                       close(0);
+                       if (execprogl("refile", "refile", "-file",
+                                       original_draft, "+trash",
+                                       (char *)NULL) != 0) {
                                advise(NULL, "unable to trash the draft");
                        }
+                       dup2(dupfd, 0);
+                       close(dupfd);
                }
                break;