Exemple #1
0
        public static bool ShowInfo(object what)
        {
            if(what == null) return false;

            // -----------------------------------------------------------------
            // Server
            // -----------------------------------------------------------------
            if(what is string)
            {
                ListOutput(0, "          ", "Server Information for: " + App.ServerName);
                ListOutput(1, "Security  ", App.Connection.TlsMode.ToString());
                ListOutput(1, "Timeout   ", App.Connection.TransportTimeout.ToString() + " [s]");

                ListOutput(2, "Greeting  ", App.Connection.ProtocolLayer.ServerGreeting);
                ListOutput(1, "Type      ", App.Server.ServerType + " (Subtype: " +
                                            App.Server.ServerSubtype + ")");
                ListOutput(1, "Admin     ", App.Server.IsAdmin ? "yes" : "no");

                ListOutput(2, "Capability", string.Join(" ", App.Factory.Capabilities));
                ListOutput(1, "Rights    ", App.EnableRights ? "enabled" : "disabled");
                string sout = "disabled";
                if(App.EnableQuota)
                    sout = string.Format("enabled (STORAGE={0} MESSAGE={1})",
                                         App.Server.HasLimit("STORAGE") ? "yes" : "no",
                                         App.Server.HasLimit("MESSAGE") ? "yes" : "no");
                ListOutput(1, "Quota     ", sout);

                ListOutput(5, "Namespace ", "Personal=" + App.Server.NamespaceDataPersonal + "\n" +
                                            "Others  =" + App.Server.NamespaceDataOther + "\n" +
                                            "Shared  =" + App.Server.NamespaceDataShared + "\n" +
                                            "Search  =" + App.Server.NamespaceDataSearch);
                return true;
            }

            // -----------------------------------------------------------------
            // Application
            // -----------------------------------------------------------------
            if(what == App)
            {
                ListOutput(0, "          ", "Application Information");
                ListOutput(1, "Runtime   ",
                           System.Environment.Version.ToString() + " (" +
                           System.Environment.OSVersion.ToString() + ")" );
                ListOutput(1, "Version   ",
                           System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
            #if DEBUG
                           + " (DEBUG build)"
            #endif
                           );

                App.Export.Open(null, (char)0, false, false);
                string bfld = ZIMapExport.BaseFolder;
                ListOutput(2, "Path      ", (bfld == "") ? "[not set]" : bfld);

                long mem1 = GC.GetTotalMemory(false) / 1024; Cache.Data.Clear(CacheData.Info.All);
                long mem2 = GC.GetTotalMemory(true)  / 1024;
                ListOutput(5, "Memory    ", string.Format("{0} kByte (minimum is {1} kByte)",
                                                          mem1, mem2));
                return true;

            }

            // -----------------------------------------------------------------
            // Mailbox
            // -----------------------------------------------------------------
            if(what is ZIMapApplication.MailBox)
            {
                ZIMapApplication.MailBox mbox = (ZIMapApplication.MailBox)what;
                ListOutput(0, "          ", "Mailbox Information");
                string msg = mbox.Name;
                if(mbox.Name ==  App.MailboxName)
                    msg = string.Format("{0} (current {1})", msg,
                          App.MailboxIsReadonly ? "Read-Only" : "Writable");
                else
                    msg += " (not current)";
                ListOutput(1, "Mailbox   ", msg);
                ListOutput(1, "Messages  ",
                              string.Format("{0} mails ({1} recent {2} unseen)",
                              mbox.Messages, mbox.Recent, mbox.Unseen));
                ListOutput(1, "Subscribed", mbox.Subscribed ? "yes" : "no");
                ListOutput(2, "Flags     ", string.Join(" ", mbox.Flags));
                ListOutput(1, "Attributes", string.Join(" ", mbox.Attributes));
                string qroot, storage, message;
                FormatQuota(mbox.Name, out storage, out message, out qroot);
                if(qroot == null)
                    ListOutput(5, "Quota     ",      "-none-");
                else
                {   if(message != null) message = "\n" + message;
                    if(storage != null) storage = "\n" + storage;
                    ListOutput(5, "Quota     ",      "Quota Root : " +
                                   qroot + message + storage);
                }
                return true;
            }

            // -----------------------------------------------------------------
            // Mail Item
            // -----------------------------------------------------------------
            if(what is uint[])
            {   uint[] uarg = (uint[])what;
                ZIMapApplication.MailInfo[] mails = Cache.Data.Headers.Array(0);

                uint uuid = uarg[0];
                uint urun;
                for(urun=0; urun < mails.Length; urun++)
                    if(mails[urun].UID == uuid) break;
                if(urun >= mails.Length)
                {   Error("UID not found: " + uuid);
                    return false;
                }
                ZIMapApplication.MailInfo mail = mails[urun];
                ZIMapMessage mesg = new ZIMapMessage();
                if(!mesg.Parse(mail.Literal, false)) return false;

                ZIMapMessage.BodyInfo info = null;
                ZIMapCommand.Fetch cmd = new ZIMapCommand.Fetch(App.Factory);
                cmd.UidCommand = App.EnableUidCommands;
                if((uarg[1] & 2) != 0)
                    cmd.Queue(uuid, "BODY BODY.PEEK[TEXT]");
                else
                    cmd.Queue(uuid, "BODY");
                if(!cmd.CheckSuccess("Failed to get status")) return false;
                if((uarg[1] & 2) != 0)
                {   if(cmd.Result.Literals == null || cmd.Result.Literals.Length < 1)
                    {  Info("Message has no body");
                       return true;
                    }
                    mesg.ParseBody(cmd.Result.Literals[0], 0);
                }
                string[] parts = cmd.Items[0].Parts;
                if(parts != null && parts.Length > 1 && parts[0] == "BODY")
                    info = ZIMapMessage.ParseBodyInfo(parts[1]);

                uint utxt = ListOutput(0, "          ", "Mail Information");

                ListOutput(1, "Item      ", string.Format("{0} (ID={1}  UID={2})",
                                            urun+1, mail.Index, mail.UID));
                ListOutput(1, "From      ", mesg.From);
                ListOutput(1, "To        ", mesg.To);
                ListOutput(1, "Subject   ", mesg.Subject);
                ListOutput(1, "Date      ", mesg.DateISO);
                ListOutput(1, "Size      ", mail.Size.ToString());

                ListOutput(2, "Flags     ", string.Join(" ", mail.Flags));

                if(info != null && info.Parts != null)
                    for(int irun=0; irun < info.Parts.Length; irun++)
                    {   string text = info.Parts[irun].ToString();
                        int icol = text.IndexOf(':');
                        if(icol > 0) text = text.Substring(icol+2);
                        ListOutput((uint)((irun == 0) ? 2 : 1),
                                   ("Part [" + info.Parts[irun].Level + "]").PadRight(10), text);
                     }

                if((uarg[1] & 1) != 0)
                {
                    List<string> llis = new List<string>();
                    //string[] names = item.FieldNames;
                    for(int irun=0; irun < mesg.HeaderCount; irun++)
                    {   string[] lines = TextTool.TextIndent(mesg.FieldKey(irun).PadRight(15) + "  " +
                                                  mesg.FieldText(irun), 17, utxt);
                        llis.AddRange(lines);
                    }
                    if(llis.Count == 0)
                        ListOutput(5, "Headers   ", "-none-");
                    if(llis.Count == 1)
                        ListOutput(5, "Headers   ", llis[0]);
                    else for(int irun=0; irun < llis.Count; irun++)
                    {   if(irun == 0)
                            ListOutput(2, "Headers   ", llis[0]);
                        else
                            ListOutput(1, "          ", llis[irun]);
                    }
                }

                if(mesg.BodyCount > 0)
                {   StringBuilder sb = new StringBuilder();
                    for(int irun=0; irun < mesg.BodyCount; irun++)
                        sb.AppendLine(mesg.BodyLine(irun, null));
                    ListOutput(2, "Body Text ", sb.ToString());
                }
                TextTool.Formatter.WriteLine(
                    TextTool.DecoLine(TextTool.Decoration.Double, 0, utxt+12));
                return true;
            }

            return false;
        }