Back to index

courier  0.68.2
maildirrequota.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2002 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "config.h"
00007 #include      <stdlib.h>
00008 #include      <string.h>
00009 #include      <stdio.h>
00010 #include      <ctype.h>
00011 #include      "maildirrequota.h"
00012 
00013 
00014 char *maildir_requota(const char *oldname, unsigned long s)
00015 {
00016 char   buf[40];
00017 char   *p;
00018 const char *q;
00019 
00020        sprintf(buf, ",S=%lu", s);
00021 
00022        if ((p=malloc(strlen(oldname)+strlen(buf)+1)) == 0)     return (0);
00023 
00024        if ((q=strrchr(oldname, '/')) == 0)       q=oldname;
00025        while (*q)
00026        {
00027               if ((*q == ',' && q[1] == 'S' && q[2] == '=') || *q == MDIRSEP[0])
00028               {
00029                      memcpy(p, oldname, q-oldname);
00030                      strcpy(p + (q-oldname), buf);
00031 
00032                      if (*q == ',')       q += 3;
00033 
00034                      for ( ; isdigit((int)(unsigned char)*q); q++)
00035                             ;
00036                      strcat(p, q);
00037                      return (p);
00038               }
00039               ++q;
00040        }
00041        return (strcat(strcpy(p, oldname), buf));
00042 }