Example #1
0
	public bool RefetchMailFlags(Mail email) {
			        throw new Exception("Not yet implemented !");
					        return false;
	}
Example #2
0
/*
 *
 *		Methods
 *
 *
 */

	public bool AppendMail(string mailbox, Mail email) {
		try {
            if(!_connected) throw new Exception("You must connect first !");
			if(!_authenticated)throw new Exception("You must authenticate first !");
			string flags = String.Empty;
			string size = (email.Body.Length-1).ToString();
			if(email.Flags.Count>0){
				flags = "(";
				foreach(Flag f in email.Flags){ flags += f.Name + " "; }
				flags = flags.Substring(0,flags.Length-1);
				flags += ")";
			}
            string command = this.Tag + "APPEND "+mailbox+" "+flags+" {"+size+"}\r\n";
            SendCommand(command);
            string response = ReadLine();
			if(response.StartsWith("+")){	
				SendCommand(email.Body);	
    	        response = ReadLine();
			}
            return true;
        } catch (Exception e) {
            this._lasterror = "AppendMail : " + e.Message;
            return false;
        }	
	}
Example #3
0
	public MailCollection FetchMessages(string start,string end,bool uid,bool headersonly,bool setseen) {
		try {
			if(!_connected) 	throw new Exception("You must connect first !");
   	     	if(!_authenticated)	throw new Exception("You must authenticate first !");
    	    if(!_selected)		throw new Exception("You must select first !");
			string UID,HEADERS,SETSEEN;
			UID = HEADERS = SETSEEN = String.Empty;
			if(uid)UID="UID ";
			if(headersonly)HEADERS="HEADER";
			if(setseen)SETSEEN=".PEEK";
			string tag = this.Tag;
			string command = tag + UID + "FETCH " + start + ":" + end + " (UID RFC822.SIZE FLAGS BODY" + SETSEEN + "[" + HEADERS + "])\r\n";
	        SendCommand(command);
			MailCollection x = new MailCollection();
			string reg = @"\* \d+ FETCH.*?BODY.*?\{(\d+)\}";
			string response = ReadLine();
			Match m = Regex.Match(response,reg);
			while(m.Groups.Count > 1){
				int bodylen = Convert.ToInt32(m.Groups[1].ToString());
				Mail mail = new Mail();
				byte[] body = ReadData(bodylen);
				Match m2 = Regex.Match(response,@"UID (\d+)");
				if(m2.Groups[1]!=null)mail.Uid = m2.Groups[1].ToString();
				m2 = Regex.Match(response,@"FLAGS \((.*?)\)");
				if(m2.Groups[1]!=null)mail.SetFlags(m2.Groups[1].ToString());
				m2 = Regex.Match(response,@"RFC822\.SIZE (\d+)");
				if(m2.Groups[1]!=null)mail.Size = Convert.ToInt32(m2.Groups[1].ToString());
				mail.Load(body,headersonly);
				x.Add(mail);
				response = ReadLine(); // read last line terminated by )
				response = ReadLine(); // read next line
		        m = Regex.Match(response,reg);
			}
			return x;
		} catch (Exception e) {
			this._lasterror = "FetchMessages " + e.ToString();//e.Message;
            return null;
		}
	 }
Example #4
0
		public void Add(Mail mail){
	 		this.List.Add(mail);
		}