~ubuntu-branches/ubuntu/lucid/beagle/lucid

« back to all changes in this revision

Viewing changes to beagled/xemail-net/src/Attachment.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Attachment.cs
 
3
 * Copyright (C) 2006 COLIN Cyrille.
 
4
 *
 
5
 */
 
6
 
 
7
using System;
 
8
using System.IO;
 
9
using System.Text.RegularExpressions;
 
10
using System.Collections;
 
11
 
 
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=");}
 
20
      }
 
21
    private string Charset {
 
22
         get { return GetHeader("charset=");}
 
23
        }
 
24
    private string ContentDisposition {
 
25
         get { return GetHeader("Content-Disposition: ");}
 
26
        }
 
27
    public string ContentEncoding {
 
28
         get { return GetHeader("Content-Transfer-Encoding: ");}
 
29
        }
 
30
    public string ContentType {
 
31
         get { return GetHeader("Content-Type: ");}
 
32
      }
 
33
    public bool IsAttachment {
 
34
      get {
 
35
        return (ContentDisposition.ToLower() == "attachment" || ContentDisposition.ToLower() == "inline")?true:false;
 
36
      }
 
37
    }
 
38
    public void Save (string path) {
 
39
      if (File.Exists(path+this.FileName)) {
 
40
          }
 
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)));
 
45
      } else {
 
46
        w.Write(_content);
 
47
      }
 
48
          w.Close();
 
49
          fs.Close();
 
50
    }
 
51
    public byte[] Content {
 
52
         set { this._content = value;}
 
53
         get { return this._content;}
 
54
      }
 
55
    public string Header {
 
56
         set { this._header = value;}
 
57
         get { return this._header;}
 
58
      }
 
59
    public bool OnServer {
 
60
         set { this._onserver = value;}
 
61
         get { return this._onserver;}
 
62
    }
 
63
    private string GetHeader(string header) {
 
64
            Match m;
 
65
            m = Regex.Match(this._header,header+"[\"]?(.*?)[\"]?(\\r\\n|;)",RegexOptions.Multiline);
 
66
            if(m.Groups.Count > 1) {
 
67
                return m.Groups[1].ToString();
 
68
            } else {
 
69
                return String.Empty;
 
70
            }
 
71
        }
 
72
 
 
73
  }
 
74
}