summaryrefslogtreecommitdiff
path: root/mono/HeaderList.custom
blob: 9cea7377ba3e4a716804ace0aa7b25fcbfc91d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
		[DllImport ("gmime")]
		static extern IntPtr g_mime_header_list_set (IntPtr raw, IntPtr name, IntPtr value);
		
		[DllImport ("gmime")]
		static extern IntPtr g_mime_header_list_get (IntPtr raw, IntPtr name);
		
		public string this[string name] {
			get {
				if (name == null)
					throw new ArgumentNullException ("name");
				
				IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
				IntPtr raw_ret = g_mime_header_list_get (Handle, native_name);
				string ret = GLib.Marshaller.Utf8PtrToString (raw_ret);
				GLib.Marshaller.Free (native_name);
				
				return ret;
			}
			
			set {
				if (name == null)
					throw new ArgumentNullException ("name");
				
				IntPtr native_name = GLib.Marshaller.StringToPtrGStrdup (name);
				IntPtr native_value = GLib.Marshaller.StringToPtrGStrdup (value);
				g_mime_header_list_set (Handle, native_name, native_value);
				GLib.Marshaller.Free (native_value);
				GLib.Marshaller.Free (native_name);
			}
		}
		
		[DllImport ("gmime")]
		static extern bool g_mime_header_list_get_iter (IntPtr raw, IntPtr iter);
		
		internal HeaderIter GetIter ()
		{
			HeaderIter iter = new HeaderIter ();
			
			g_mime_header_list_get_iter (Handle, iter.Handle);
			
			return iter;
		}
		
		public IEnumerator GetEnumerator ()
		{
			return new HeaderEnumerator (this);
		}
		
		public StreamWrapper Stream {
			get {
				GMime.StreamMem mem_stream = new GMime.StreamMem ();
				this.WriteToStream (mem_stream);
				mem_stream.Seek (0);
				return new StreamWrapper (mem_stream);
			}
		}