X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Ffolder_addmsg.c;h=a0595e6ecab1093ff6b79f47d9edb349851c6928;hb=mmh-start;hp=f03d386d6a748f1d78f40b6d3b31c108800e01a6;hpb=40d8dba250400b613688f3c2824ec81a0b76b168;p=mmh diff --git a/sbr/folder_addmsg.c b/sbr/folder_addmsg.c index f03d386..a0595e6 100644 --- a/sbr/folder_addmsg.c +++ b/sbr/folder_addmsg.c @@ -2,8 +2,6 @@ /* * folder_addmsg.c -- Link message into folder * - * $Id$ - * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. @@ -20,41 +18,32 @@ int folder_addmsg (struct msgs **mpp, char *msgfile, int selected, - int unseen, int preserve, int deleting) + int unseen, int preserve, int deleting, char *from_dir) { - int infd, outfd, linkerr, first_time, msgnum; + int infd, outfd, linkerr, msgnum; char *nmsg, newmsg[BUFSIZ]; char oldmsg[BUFSIZ]; struct msgs *mp; struct stat st1, st2; - first_time = 1; /* this is first attempt */ mp = *mpp; + /* should we preserve the numbering of the message? */ + if (preserve && (msgnum = m_atoi (msgfile)) > 0) { + ; + } else if (mp->nummsg == 0) { + /* check if we are adding to empty folder */ + msgnum = 1; + } else { + /* else use highest message number + 1 */ + msgnum = mp->hghmsg + 1; + } + /* * We might need to make several attempts * in order to add the message to the folder. */ - for (;;) { - /* - * Get the message number we will attempt to add. - */ - if (first_time) { - /* should we preserve the numbering of the message? */ - if (preserve && (msgnum = m_atoi (msgfile)) > 0) { - ; - } else if (mp->nummsg == 0) { - /* check if we are adding to empty folder */ - msgnum = 1; - } else { - /* else use highest message number + 1 */ - msgnum = mp->hghmsg + 1; - } - first_time = 0; - } else { - /* another attempt, so try next higher message number */ - msgnum++; - } + for (;; msgnum++) { /* * See if we need more space. If we need space at the @@ -137,12 +126,12 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, * Then run the external hook on the message if one was specified in the context. * Run the refile hook if we're moving the message from one place to another. * We have to construct the from path name for this because it's not there. - * Run the add hook if the message is getting copied or lined somewhere else. + * Run the add hook if the message is getting copied or linked somewhere else. */ if (link (msgfile, newmsg) != -1) { if (deleting) { - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", pwd(), msgfile); + (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); (void)ext_hook("ref-hook", oldmsg, newmsg); } else @@ -180,11 +169,11 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, */ if (linkerr == EXDEV) { if (stat (newmsg, &st1) == 0) { - advise (NULL, "message %s:%s already exists", newmsg); + advise (NULL, "message %s:%s already exists", mp->foldpath, newmsg); return -1; } else { if ((infd = open (msgfile, O_RDONLY)) == -1) { - advise (msgfile, "unable to open message %s"); + advise (msgfile, "unable to open message %s", msgfile); return -1; } fstat (infd, &st1); @@ -197,8 +186,10 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, close (infd); close (outfd); - if (deleting) - (void)ext_hook("ref-hook", newmsg, msgfile); + if (deleting) { + (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); + (void)ext_hook("ref-hook", oldmsg, newmsg); + } else (void)ext_hook("add-hook", newmsg, (char *)0);