/[mailutils]/mailutils/imap4d/status.c
ViewVC logotype

Diff of /mailutils/imap4d/status.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by gray, Tue Feb 19 17:06:49 2002 UTC revision 1.12 by gray, Wed Feb 20 15:38:51 2002 UTC
# Line 21  Line 21 
21   *   *
22   */   */
23    
24    typedef int (*status_funcp) __P ((mailbox_t));
25    
26  static int status_messages    __P ((mailbox_t));  static int status_messages    __P ((mailbox_t));
27  static int status_recent      __P ((mailbox_t));  static int status_recent      __P ((mailbox_t));
28  static int status_uidnext     __P ((mailbox_t));  static int status_uidnext     __P ((mailbox_t));
29  static int status_uidvalidity __P ((mailbox_t));  static int status_uidvalidity __P ((mailbox_t));
30  static int status_unseen      __P ((mailbox_t));  static int status_unseen      __P ((mailbox_t));
31    
32    struct status_table {
33      char *name;
34      status_funcp fun;
35    } status_table[] = {
36      "MESSAGES", status_messages,
37      "RECENT", status_recent,
38      "UIDNEXT", status_uidnext,
39      "UIDVALIDITY", status_uidvalidity,
40      "UNSEEN", status_unseen,
41      NULL
42    };
43    
44    static status_funcp
45    status_get_handler (const char *name)
46    {
47      struct status_table *p;
48    
49      for (p = status_table; p->name; p++)
50        if (strcmp (p->name, name) == 0)
51          return p->fun;
52      return NULL;
53    }
54      
55  int  int
56  imap4d_status (struct imap4d_command *command, char *arg)  imap4d_status (struct imap4d_command *command, char *arg)
57  {  {
# Line 36  imap4d_status (struct imap4d_command *co Line 61  imap4d_status (struct imap4d_command *co
61    const char *delim = "/";    const char *delim = "/";
62    mailbox_t smbox = NULL;    mailbox_t smbox = NULL;
63    int status;    int status;
64      int count = 0;
65    
66    if (! (command->states & state))    if (! (command->states & state))
67      return util_finish (command, RESP_BAD, "Wrong state");      return util_finish (command, RESP_BAD, "Wrong state");
# Line 48  imap4d_status (struct imap4d_command *co Line 74  imap4d_status (struct imap4d_command *co
74    if (strcasecmp (name, "INBOX") == 0 && !mu_virtual_domain)    if (strcasecmp (name, "INBOX") == 0 && !mu_virtual_domain)
75      {      {
76        struct passwd *pw = mu_getpwuid (getuid());        struct passwd *pw = mu_getpwuid (getuid());
77        mailbox_name = strdup ((pw) ? pw->pw_name : "");        if (!pw)
78            return util_finish (command, RESP_NO, "Cannot map UID to username");
79          mailbox_name = malloc (strlen (maildir) + strlen (pw->pw_name) + 1);
80          if (!mailbox_name)
81            {
82              syslog (LOG_ERR, "Not enough memory");
83              return util_finish (command, RESP_NO, "Not enough memory");
84            }
85          sprintf (mailbox_name, "%s%s", maildir, pw->pw_name);
86      }      }
87    else    else
88      mailbox_name = namespace_getfullpath (name, delim);      mailbox_name = namespace_getfullpath (name, delim);
# Line 63  imap4d_status (struct imap4d_command *co Line 97  imap4d_status (struct imap4d_command *co
97        if (status == 0)        if (status == 0)
98          {          {
99            char item[32];            char item[32];
           util_send ("* STATUS %s (", name);  
100            item[0] = '\0';            item[0] = '\0';
101              
102              if (*sp == '(')
103                sp++;
104              else
105                *sp = 0;
106              
107            /* Get the status item names.  */            /* Get the status item names.  */
108            while (*sp && *sp != ')')            while (*sp && *sp != ')')
109              {              {
110                int err = 1;                int err = 1;
111                  status_funcp fun;
112                  
113                util_token (item, sizeof (item), &sp);                util_token (item, sizeof (item), &sp);
114                if (strcasecmp (item, "MESSAGES") == 0)                fun = status_get_handler (item);
115                  err = status_messages (smbox);                if (!fun)
116                else if (strcasecmp (item, "RECENT") == 0)                  {
117                  err = status_recent (smbox);                    count = -1;
118                else if (strcasecmp (item, "UIDNEXT") == 0)                    break;
119                  err = status_uidnext (smbox);                  }
120                else if (strcasecmp (item, "UIDVALIDITY") == 0)                    
121                  err = status_uidvalidity (smbox);                if (count++ == 0)
122                else if (strcasecmp (item, "UNSEEN") == 0)                  util_send ("* STATUS %s (", name);
123                  err = status_unseen (smbox);  
124                if (!err)                if (!fun (smbox))
125                  util_send (" ");                  util_send (" ");
126              }              }
127            util_send (")\r\n");            if (count)
128                util_send (")\r\n");
129            mailbox_close (smbox);            mailbox_close (smbox);
130          }          }
131        mailbox_destroy (&smbox);        mailbox_destroy (&smbox);
132      }      }
133    free (mailbox_name);    free (mailbox_name);
134    
135    if (status == 0)    if (count == 0)
136        return util_finish (command, RESP_BAD, "Too few args (empty list)");
137      else if (count == -1)
138        return util_finish (command, RESP_BAD, "Invalid flag in list");
139      else if (status == 0)
140      return util_finish (command, RESP_OK, "Completed");      return util_finish (command, RESP_OK, "Completed");
141    return util_finish (command, RESP_NO, "Error opening mailbox");    return util_finish (command, RESP_NO, "Error opening mailbox");
142  }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26