using System;
using System.Windows.Forms;
using System.Collections.Generic;

class MailBox
{
    #region Getter

    public String Sender
    {
        get;
        private set;
    }

    public String Date
    {
        get;
        private set;
    }

    public String Content
    {
        get;
        private set;
    }

    public List<MailBox> Messages
    {
        get;
        private set;
    }

    #endregion

    public MailBox(String token)
    {
        Messages = new List<MailBox>();

        String[] msg = token.Split(new String[] { "Weiterleiten" }, StringSplitOptions.RemoveEmptyEntries);

        for (int i = 0; i < msg.Length - 1; i++)
        {
            Sender = Split(msg[i], "°14°_°BB>_h", 1).Split('|')[0];
            Date = Split(msg[i], "|/w \"<°°°_#", 1).Split('#')[0];
            Content = Split(Split(msg[i], "°>left<°°+0011r+509°", 1), "°+5000°°r°°", 0);
            Content = Content.Remove(Content.Length - 1);

            Messages.Add(new MailBox(Sender, Date, Content));
        }
    }

    public void Show()
    {
        foreach (MailBox mBox in Messages)
        {
            MessageBox.Show(String.Format("Absender: {0}\nDatum: {1}\nNachricht:\n{2}", mBox.Sender, mBox.Date, mBox.Content), 
                            "Neue Nachricht", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }

    private MailBox(String sender, String date, String content)
    {
        this.Sender = sender;
        this.Date = date;
        this.Content = content;
    }

    private String Split(String str, String separator, int index)
    {
        try
        {
            return str.Split(new String[] { separator }, StringSplitOptions.RemoveEmptyEntries)[index];
        }
        catch (IndexOutOfRangeException)
        {
            return String.Empty;
        }
    }
}
