OWASP O2 Platform Blog

Example of creating, consuming and serializing C# classes

I’m currently helping Sarah Baso (from OWASP) to use O2 to streamline a number of OWASP admin tasks, and here are a couple script samples from the code that she is writing on retrieving details from Mailman Mailing lists

Here is the base class with data

// This file is part of the OWASP O2 Platform (http://www.owasp.org/index.php/OWASP_O2_Platform) and is released under the Apache 2.0 License (<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)
using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using O2.Kernel;
using O2.Kernel.ExtensionMethods;
using O2.DotNetWrappers.DotNet;
using O2.DotNetWrappers.Windows;
using O2.DotNetWrappers.ExtensionMethods;
using O2.Views.ASCX.classes.MainGUI;
using O2.Views.ASCX.ExtensionMethods;
namespace O2.Script
    public class MailingLists
        public DateTime             DateCollected    { get; set;}
        public List<MailingList> Lists          { get; set; }
        public MailingLists()
            Lists = new List<MailingList>();
    public class MailingList
        public string Name                     { get; set; }
        public bool  Public                 { get; set; }       
        public List<Subscriber> Admins        { get; set; }
        public List<Subscriber> Subscribers { get; set; }       
        public MailingList()
            Admins = new List<Subscriber>();
            Subscribers = new List<Subscriber>();
    public class Subscriber
        public string Name           { get; set; }
        public string Email       { get; set; }       

Here is how that data can be consumed

var mailingLists = new MailingLists();</pre>
Action<string, bool> addList =
    (listName, isPublic)=>
            var mailingList = new MailingList();
            mailingList.Name = listName;
            mailingList.Public = isPublic;           
addList("owasp-london", true);
addList("owasp-rh", true);
addList("owasp-chapter", true);
/*var londonList = new MailingList();
londonList.Name = "Owasp-london";
londonList.Public = true;


var chaptersList = new MailingList();
chaptersList.Name = "Owasp-chapter";
chaptersList.Public = true;


//return mailingLists;
//return myData;
var result = mailingLists.serialize(false);

return mailingLists;
//using O2.Script    
//O2File:C:\O2\_XRules_Local\Sarah's Test\MyData.cs

Here is how to normalize the email addresses

var url = https://lists.owasp.org/mailman/options/owasp-xyz-list/aaa_at_gmail.com;

if (url.contains("https://lists.owasp.org/mailman/options/"))
    var items = url.remove("https://lists.owasp.org/mailman/options/").split("/");
    var listName = items[0];
    var email = items[1].replace("_at_","@");
    return email;

return "no data";

February 5, 2012 - Posted by | Mailman, OWASP

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: