using System; using System.Collections; using System.ComponentModel; using System.Runtime.InteropServices; namespace Camel { [StructLayout (LayoutKind.Sequential)] public struct CamelException { public int id; public string desc; } public class Arg { public enum Tag : uint { END = 0, IGNORE = 1, FIRST = 1024, TYPE = 0xf0000000, /* type field for tags */ TAG = 0x0fffffff, /* tag field for args */ OBJ = 0x00000000, /* object */ INT = 0x10000000, /* int */ DBL = 0x20000000, /* double */ STR = 0x30000000, /* c string */ PTR = 0x40000000, /* ptr */ BOO = 0x50000000 /* bool */ } } public class Exception : System.ApplicationException { public enum Type { NONE = 0, SYSTEM = 1 } public Type id; public string desc; public Exception(CamelException ex) { id = (Type)ex.id; desc = ex.desc; } public Exception(Type _id, string _desc) { id = _id; desc = _desc; } } public class Util { [DllImport("camel-1.2")] static extern int camel_init(string certdir, bool nss); public static void Init(string certdir, bool nss) { if (camel_init(certdir, nss) != 0) throw new Exception(Exception.Type.SYSTEM, "Init failure"); } public static string [] getUIDArray(IntPtr o) { GPtrArray pa = (GPtrArray)Marshal.PtrToStructure(o, typeof(GPtrArray)); string [] uids = new string[pa.len]; for (int i=0;i use StringBuilder [DllImport("camel-1.2")] static extern IntPtr camel_url_decode(ref string url); public URL(string uri) { CamelException ex = new CamelException(); cobject = camel_url_new(uri, ref ex); if (ex.id != 0) throw new Exception(ex); } public URL(URL bbase, string uri) { cobject = camel_url_new_with_base(bbase.cobject, uri); } ~URL() { camel_url_free(cobject); } /* its ugly but it works */ private string field(string name) { return Marshal.PtrToStringAuto(Marshal.ReadIntPtr(cobject, (int)Marshal.OffsetOf(typeof(CamelURL), name))); } public string protocol { set { camel_url_set_protocol(cobject, value); } get { return field("protocol"); } } public string user { set { camel_url_set_user(cobject, value); } get { return field("user"); } } public string authmech { set { camel_url_set_authmech(cobject, value); } get { return field("authmech"); } } public string passwd { set { camel_url_set_passwd(cobject, value); } get { return field("passwd"); } } public string host { set { camel_url_set_host(cobject, value); } get { return field("host"); } } public int port { set { camel_url_set_port(cobject, value); } get { return (int)Marshal.ReadIntPtr(cobject, (int)Marshal.OffsetOf(typeof(CamelURL), "port")); } } public string path { set { camel_url_set_path(cobject, value); } get { return field("path"); } } public string query { set { camel_url_set_query(cobject, value); } get { return field("query"); } } public string fragment { set { camel_url_set_fragment(cobject, value); } get { return field("fragment"); } } public Params paramlist { get { if (param_list == null) param_list = new Params(this); return param_list; } } public override string ToString() { return camel_url_to_string(cobject, 0); } public static string encode(string val) { return camel_url_encode(val, null); } public static string encode(string val, string escape) { return camel_url_encode(val, escape); } } } namespace Camel.Hash { public class Stream : System.IO.Stream { protected Camel.Stream substream; public Stream(Camel.Stream sub) { substream = sub; } public override bool CanSeek { get { return false; } } public override bool CanRead { get { return true; } } public override bool CanWrite { get { return true; } } public override long Length { get { throw new System.IO.IOException("Cannot get stream length"); } } public override long Position { get { throw new System.IO.IOException("Cannot get stream position"); } set { if (value == 0) { substream.reset(); } else { throw new System.IO.IOException("Cannot set stream position"); } } } public override int Read(byte[] buffer, int offset, int count) { // FIXME: how to add the offset to the buffer? return substream.read(buffer, count); } public override void Write(byte[] buffer, int offset, int count) { // FIXME: how to add the offset to the buffer? substream.write(buffer, count); } public override void Flush() { substream.flush(); } public override long Seek(long offset, System.IO.SeekOrigin seek) { throw new System.IO.IOException("Seeking not supported"); } public override void SetLength(long len) { throw new System.IO.IOException("Cannot set stream length"); } } } /* namespace Evolution.Mail { class Component : GLib.Object { public Component(IntPtr raw) : base(raw) {} public Component() : base() {} ~Component() { Dispose(); } [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek(); [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek_base_directory(IntPtr component); [DllImport("libevolution-mail.so")] static extern IntPtr mail_component_peek(); public static Component peek() { return new Component(mail_component_peek()); } public String baseDirectory { get {} } } */