Exemplo n.º 1
0
        // =============================================================================
        // List Formatter for mailboxes
        // =============================================================================
        // TODO: ListFolders header text argument
        private static bool ListFolders(CacheData.MBoxRef mailboxes, string title,
                                        bool bSubscr, bool bDetail, bool bRights, bool bQuota)
        {
            uint ubox = mailboxes.Count;
            if(ubox == 0) return false;
            if(!App.EnableRights) bRights = false;
            if(!App.EnableQuota)  bQuota  = false;

            uint ucol = 1;
            if(bDetail)  ucol += 3;
            if(bSubscr)  ucol++;
            if(bRights)  ucol++;
            if(bQuota)   ucol++;
            TextTool.TableBuilder table = GetTableBuilder(ucol);
            object[] data = new object[ucol];
            ucol = 0;
            data[ucol] = title;
            table.Columns[ucol].MaxWidth   = 20;
            table.Columns[ucol++].MinWidth = 34;    // name

            if(bSubscr)
                data[ucol++] = "Sub";
            if(bDetail)                             // messages
            {   data[ucol] = "Mails";
                table.Columns[ucol++].MinWidth = 6;
                data[ucol] = "Recent";
                table.Columns[ucol++].MinWidth = 6;
                data[ucol] = "Unseen";
                table.Columns[ucol++].MinWidth = 6;
            }
            if(bRights)
            {   data[ucol] = "Rights";
                table.Columns[ucol].RigthAlign = false;
                table.Columns[ucol++].MinWidth = 6;
            }
            if(bQuota)
            {   data[ucol] = "Size Quota";
                table.Columns[ucol++].MinWidth = 12;
            }

            // print a list ...
            uint nmsg = 0;
            uint nrec = 0;
            uint nuns = 0;
            uint scnt = 0;
            uint nlas = 0;                      // last NS seen
            bool bsep = false;                  // separator on NS change

            table.Header(data);
            string subs = Ascii ? "*" : "■";    // HACK: for mono no "✓";

            mailboxes.Reset();
            while(mailboxes.Next())
            {   // get name, copy MailBox - we need it frequently ...
                ZIMapApplication.MailBox mailbox = mailboxes.Current;
                uint   nidx = ZIMapServer.Personal;
                string name = mailbox.Name;
                if(App.EnableNamespaces) name = App.Server.FriendlyName(name, out nidx);
                if(nidx != nlas)
                {   if(bsep) table.AddSeparator();
                    nlas = nidx;
                }
                bsep = true;

                // fill table ..
                ucol = 0;
                data[ucol++] = name;

                if(bSubscr)
                {   data[ucol++] = mailbox.Subscribed  ? subs : "";
                    if(mailbox.Subscribed) scnt++;
                }
                if(bDetail)
                {   if(mailbox.HasDetails)
                    {   data[ucol++] = mailbox.Messages;
                        data[ucol++] = mailbox.Recent;
                        data[ucol++] = mailbox.Unseen;
                    }
                    else
                    {   data[ucol++] = "-";
                        data[ucol++] = "-";
                        data[ucol++] = "-";
                    }
                }
                if(bRights)
                    data[ucol++] = mailboxes.ExtraRights;
                if(bQuota)
                {   ZIMapApplication.QuotaInfo info;
                    if(mailboxes.ExtraGetQuota(out info))
                    {   if(info.QuotaRoot != mailbox.Name)
                            data[ucol++] = string.Format("[Root={0}]", mailboxes.Search(info.QuotaRoot)+1);
                        else
                            data[ucol++] = string.Format("{0}k {1,3}%", info.StorageUsage,
                                (uint)((info.StorageUsage*100.0)/info.StorageLimit), info.QuotaRoot);
                    }
                    else
                        data[ucol++] = "";
                }
                table.AddRow(data);

                // build sums for footer line ...
                nmsg += mailbox.Messages;
                nrec += mailbox.Recent;
                nuns += mailbox.Unseen;
            }
            if(bSubscr && bDetail)
                table.Footer("Total", scnt, nmsg, nrec, nuns);
            else if(bDetail)
                table.Footer("Total", nmsg, nrec, nuns);
            else if(bSubscr)
                table.Footer("Total", scnt);
            else
                table.Footer("");
            table.PrintTable();
            return true;
        }
Exemplo n.º 2
0
        /// <summary>List subscribed mailboxes only</summary>
        public static bool ListSubscribed(CacheData.MBoxRef mailboxes,
                                          bool bDetail, bool bRights, bool bQuota)
        {
            if(mailboxes.IsNothing) return false;
            Cache.ListedFolders = mailboxes;

            // count subscriptions ...
            uint usub = 0;
            mailboxes.Reset();
            while(mailboxes.Next())
                if(mailboxes.Subscribed) usub++;
            if(usub == 0)
            {   Message(FormatFilter("No subscribed mailboxes"));
                return true;
            }

            // create subset ...
            if(usub != mailboxes.Count)
            {   ZIMapApplication.MailBox[] subs = new ZIMapApplication.MailBox[usub];
                usub = 0;
                mailboxes.Reset();
                while(mailboxes.Next())
                    if(mailboxes.Subscribed) subs[usub++] = mailboxes.Current;
                mailboxes = new CacheData.MBoxRef(subs);
            }

            return ListFolders(mailboxes, FormatFilter("Subscribed Mailboxes"),
                               false, bDetail, bRights, bQuota);
        }