X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffolder_addmsg.c;h=e14c7099d69099a494a29cb3cd23212df598d898;hp=5d1690e03618869a1e35c17e23559f5bbbaf67a7;hb=1fb6287fc4986668e8f49d7c3bdca27d53e267af;hpb=ced6090a330d3d83d0bce709f756aa3d7d65fea4 diff --git a/sbr/folder_addmsg.c b/sbr/folder_addmsg.c index 5d1690e..e14c709 100644 --- a/sbr/folder_addmsg.c +++ b/sbr/folder_addmsg.c @@ -6,9 +6,11 @@ ** complete copyright information. */ +#include #include #include #include +#include /* ** Link message into a folder. Return the new number @@ -16,7 +18,7 @@ */ int -folder_addmsg (struct msgs **mpp, char *msgfile, int selected, +folder_addmsg(struct msgs **mpp, char *msgfile, int selected, int unseen, int preserve, int deleting, char *from_dir) { int infd, outfd, linkerr, msgnum; @@ -28,7 +30,7 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, mp = *mpp; /* should we preserve the numbering of the message? */ - if (preserve && (msgnum = m_atoi (msgfile)) > 0) { + if (preserve && (msgnum = m_atoi(msgfile)) > 0) { ; } else if (mp->nummsg == 0) { /* check if we are adding to empty folder */ @@ -51,17 +53,17 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** extend message status range to cover this message number. */ if (msgnum > mp->hghoff) { - if ((mp = folder_realloc (mp, mp->lowoff, msgnum + 100))) + if ((mp = folder_realloc(mp, mp->lowoff, msgnum + 100))) *mpp = mp; else { - advise (NULL, "unable to allocate folder storage"); + advise(NULL, "unable to allocate folder storage"); return -1; } } else if (msgnum < mp->lowoff) { - if ((mp = folder_realloc (mp, msgnum, mp->hghoff))) + if ((mp = folder_realloc(mp, msgnum, mp->hghoff))) *mpp = mp; else { - advise (NULL, "unable to allocate folder storage"); + advise(NULL, "unable to allocate folder storage"); return -1; } } @@ -70,35 +72,21 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** If a message is already in that slot, ** then loop to next available slot. */ - if (does_exist (mp, msgnum)) + if (does_exist(mp, msgnum)) continue; /* setup the bit flags for this message */ - clear_msg_flags (mp, msgnum); - set_exists (mp, msgnum); + clear_msg_flags(mp, msgnum); + set_exists(mp, msgnum); /* should we set the SELECT_UNSEEN bit? */ if (unseen) { - set_unseen (mp, msgnum); + set_unseen(mp, msgnum); } /* should we set the SELECTED bit? */ if (selected) { - set_selected (mp, msgnum); - - /* check if highest or lowest selected */ - if (mp->numsel == 0) { - mp->lowsel = msgnum; - mp->hghsel = msgnum; - } else { - if (msgnum < mp->lowsel) - mp->lowsel = msgnum; - if (msgnum > mp->hghsel) - mp->hghsel = msgnum; - } - - /* increment number selected */ - mp->numsel++; + set_selected(mp, msgnum); } /* @@ -117,8 +105,8 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, /* increment message count */ mp->nummsg++; - nmsg = m_name (msgnum); - snprintf (newmsg, sizeof(newmsg), "%s/%s", mp->foldpath, nmsg); + nmsg = m_name(msgnum); + snprintf(newmsg, sizeof(newmsg), "%s/%s", mp->foldpath, nmsg); /* ** Now try to link message into folder. Then run the @@ -129,23 +117,19 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** Run the add hook if the message is getting copied or ** linked somewhere else. */ - if (link (msgfile, newmsg) != -1) { + if (link(msgfile, newmsg) != -1) { if (deleting) { - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); - (void)ext_hook("ref-hook", oldmsg, newmsg); + snprintf(oldmsg, sizeof (oldmsg), "%s/%s", + from_dir, msgfile); + ext_hook("ref-hook", oldmsg, newmsg); } else - (void)ext_hook("add-hook", newmsg, (char *)0); + ext_hook("add-hook", newmsg, NULL); return msgnum; } else { linkerr = errno; -#ifdef EISREMOTE - if (linkerr == EISREMOTE) - linkerr = EXDEV; -#endif /* EISREMOTE */ - /* ** Check if the file in our desired location is ** the same as the source file. If so, then just @@ -154,7 +138,7 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** slot (hghmsg+1). */ if (linkerr == EEXIST) { - if (stat (msgfile, &st2) == 0 && stat (newmsg, &st1) == 0 + if (stat(msgfile, &st2) == 0 && stat(newmsg, &st1) == 0 && st2.st_ino == st1.st_ino) { return msgnum; } else { @@ -169,29 +153,32 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** error, else just copy the message. */ if (linkerr == EXDEV) { - if (stat (newmsg, &st1) == 0) { - advise (NULL, "message %s:%s already exists", mp->foldpath, newmsg); + if (stat(newmsg, &st1) == 0) { + 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", msgfile); + if ((infd = open(msgfile, O_RDONLY)) == -1) { + advise(msgfile, "unable to open message %s", msgfile); return -1; } - fstat (infd, &st1); - if ((outfd = creat (newmsg, (int) st1.st_mode & 0777)) == -1) { - advise (newmsg, "unable to create"); - close (infd); + fstat(infd, &st1); + if ((outfd = creat(newmsg, (int) st1.st_mode & 0777)) == -1) { + advise(newmsg, "unable to create"); + close(infd); return -1; } - cpydata (infd, outfd, msgfile, newmsg); - close (infd); - close (outfd); + cpydata(infd, outfd, msgfile, newmsg); + close(infd); + close(outfd); if (deleting) { - (void)snprintf(oldmsg, sizeof (oldmsg), "%s/%s", from_dir, msgfile); - (void)ext_hook("ref-hook", oldmsg, newmsg); + snprintf(oldmsg, sizeof oldmsg, + "%s/%s", + from_dir, + msgfile); + ext_hook("ref-hook", oldmsg, newmsg); } else - (void)ext_hook("add-hook", newmsg, (char *)0); + ext_hook("add-hook", newmsg, NULL); return msgnum; } @@ -201,7 +188,7 @@ folder_addmsg (struct msgs **mpp, char *msgfile, int selected, ** Else, some other type of link error, ** so just return error. */ - advise (newmsg, "error linking %s to", msgfile); + advise(newmsg, "error linking %s to", msgfile); return -1; } }