Use good m_ functions, because it smell like a flower, version 2.
[apps/madmutt.git] / flags.c
diff --git a/flags.c b/flags.c
index 8e1bbdb..fc3c4b4 100644 (file)
--- a/flags.c
+++ b/flags.c
@@ -1,41 +1,31 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
- * 
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- * 
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- * 
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
+
+#include <lib-ui/curses.h>
+#include <lib-ui/menu.h>
+#include <lib-ui/sidebar.h>
+#include <lib-mx/mx.h>
 
 #include "mutt.h"
-#include "mutt_curses.h"
-#include "mutt_menu.h"
 #include "sort.h"
-#include "mx.h"
-#include "sidebar.h"
 
-#ifdef USE_IMAP
-#include "imap_private.h"
-#endif
+#include <imap/imap_private.h>
+
 
 void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 {
   int changed = h->changed;
   int deleted = ctx->deleted;
   int tagged = ctx->tagged;
+  int flagged = ctx->flagged;
 
   if (ctx->readonly && flag != M_TAG)
     return;                     /* don't modify anything if we are read-only */
@@ -43,20 +33,14 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
   switch (flag) {
   case M_DELETE:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_DELETE))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_DELETE))
+      return;
 
     if (bf) {
       if (!h->deleted && !ctx->readonly) {
         h->deleted = 1;
         if (upd_ctx)
           ctx->deleted++;
-#ifdef USE_IMAP
         /* deleted messages aren't treated as changed elsewhere so that the
          * purge-on-sync option works correctly. This isn't applicable here */
         if (ctx && ctx->magic == M_IMAP) {
@@ -64,7 +48,6 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
           if (upd_ctx)
             ctx->changed = 1;
         }
-#endif
       }
     }
     else if (h->deleted) {
@@ -75,14 +58,12 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
           ctx->appended--;
       }
       h->appended = 0;          /* when undeleting, also reset the appended flag */
-#ifdef USE_IMAP
       /* see my comment above */
       if (ctx->magic == M_IMAP) {
         h->changed = 1;
         if (upd_ctx)
           ctx->changed = 1;
       }
-#endif
       /* 
        * If the user undeletes a message which is marked as
        * "trash" in the maildir folder on disk, the folder has
@@ -117,13 +98,8 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 
   case M_NEW:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_SEEN))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_SEEN))
+      return;
 
     if (bf) {
       if (h->read || h->old) {
@@ -155,13 +131,8 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 
   case M_OLD:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_SEEN))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_SEEN))
+      return;
 
     if (bf) {
       if (!h->old) {
@@ -187,13 +158,8 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 
   case M_READ:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_SEEN))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_SEEN))
+      return;
 
     if (bf) {
       if (!h->read) {
@@ -223,13 +189,8 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 
   case M_REPLIED:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_WRITE))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_WRITE))
+      return;
 
     if (bf) {
       if (!h->replied) {
@@ -257,13 +218,8 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
 
   case M_FLAG:
 
-#ifdef USE_IMAP
-    if (ctx && ctx->magic == M_IMAP)
-      if (mutt_bit_isset (((IMAP_DATA *) ctx->data)->capabilities, ACL)
-          && !mutt_bit_isset (((IMAP_DATA *) ctx->data)->rights,
-                              IMAP_ACL_WRITE))
-        return;
-#endif
+    if (!mx_acl_check (ctx, ACL_WRITE))
+      return;
 
     if (bf) {
       if (!h->flagged) {
@@ -307,11 +263,10 @@ void _mutt_set_flag (CONTEXT * ctx, HEADER * h, int flag, int bf, int upd_ctx)
    * search results so that any future search will match the current status
    * of this message and not what it was at the time it was last searched.
    */
-  if (h->searched
-      && (changed != h->changed || deleted != ctx->deleted
-          || tagged != ctx->tagged))
+  if (h->searched && (changed != h->changed || deleted != ctx->deleted ||
+                      tagged != ctx->tagged || flagged != ctx->flagged))
     h->searched = 0;
-  draw_sidebar (0);
+  sidebar_draw ();
 }
 
 void mutt_tag_set_flag (int flag, int bf)
@@ -343,7 +298,7 @@ int mutt_thread_set_flag (HEADER * hdr, int flag, int bf, int subthread)
   if ((cur = cur->child) == NULL)
     return (0);
 
-  FOREVER {
+  for (;;) {
     if (cur->message)
       mutt_set_flag (Context, cur->message, flag, bf);