3
* Copyright (C) 2006 COLIN Cyrille.
9
using System.Text.RegularExpressions;
10
using System.Collections;
12
namespace System.Net.Imap {
13
public class Attachment {
14
private string _header = String.Empty;
15
private byte[] _content = new byte[0];
16
private bool _onserver;
17
public Attachment() {}
18
public string FileName {
19
get { return GetHeader("filename=");}
21
private string Charset {
22
get { return GetHeader("charset=");}
24
private string ContentDisposition {
25
get { return GetHeader("Content-Disposition: ");}
27
public string ContentEncoding {
28
get { return GetHeader("Content-Transfer-Encoding: ");}
30
public string ContentType {
31
get { return GetHeader("Content-Type: ");}
33
public bool IsAttachment {
35
return (ContentDisposition.ToLower() == "attachment" || ContentDisposition.ToLower() == "inline")?true:false;
38
public void Save (string path) {
39
if (File.Exists(path+this.FileName)) {
41
FileStream fs = new FileStream(path+this.FileName, FileMode.Create);
42
BinaryWriter w = new BinaryWriter(fs);
43
if(ContentEncoding == "base64") {
44
w.Write(Convert.FromBase64String(System.Text.Encoding.ASCII.GetString(_content)));
51
public byte[] Content {
52
set { this._content = value;}
53
get { return this._content;}
55
public string Header {
56
set { this._header = value;}
57
get { return this._header;}
59
public bool OnServer {
60
set { this._onserver = value;}
61
get { return this._onserver;}
63
private string GetHeader(string header) {
65
m = Regex.Match(this._header,header+"[\"]?(.*?)[\"]?(\\r\\n|;)",RegexOptions.Multiline);
66
if(m.Groups.Count > 1) {
67
return m.Groups[1].ToString();