Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Gmail Agent API v0.5 / Mail Notifier & Address Importer

, 6 Jul 2004
Open source Gmail API in C#
gmailagent-src.zip
Johnvey.GmailAgent.Applet
App.ico
bin
Debug
Release
gmail-new.ico
gmail.ico
GmailAgent.exe.manifest
Johnvey.GmailAgent.Applet.csproj.user
obj
Debug
temp
TempPE
Release
temp
TempPE
Setup
Debug
Release
Setup.vdproj
Johnvey.GmailAgent
bin
Debug
Release
Johnvey.GmailAgent.csproj.user
obj
Debug
temp
TempPE
Release
temp
TempPE
gmailagentsetup.zip
GmailAgentSetup.msi
/**************************************************************************
Gmail Agent API
Copyright (C) 2004 Johnvey Hwang

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**************************************************************************/

using System;
using System.Net;
using System.Collections;

namespace Johnvey.GmailAgent
{
	/// <summary>
	/// Represents an in-use Gmail mailbox account.
	/// </summary>
	public class GmailSession
	{

		private string _username;
		private string _password;
		private string _threadListTimestamp;
		private string _fingerprint;
		private DateTime _lastLoginTime;
		private DateTime _lastRefreshTime;
		private SortedList _defaultSearchCounts;
		private SortedList _categoryCounts;
		private CookieCollection _cookies;
		private int _totalMessages;
		private GmailThreadCollection _unreadThreads;
		private bool _hasConnectionError;

		/// <summary>
		/// Gets or sets the user's Google Accounts username.
		/// </summary>
		public string Username						{ get { return _username; } set { _username = value; } }

		/// <summary>
		/// Gets or sets the user's Google Accounts password.
		/// </summary>
		public string Password						{ get { return _password; } set { _password = value; } }
		
		/// <summary>
		/// Gets or sets the Gmail mailbox threadlist timestamp.
		/// </summary>
		public string ThreadListTimestamp			{ get { return _threadListTimestamp; } set { _threadListTimestamp = value; } }
		
		/// <summary>
		/// Gets or sets the Gmail fingerprint.
		/// </summary>
		public string Fingerprint					{ get { return _fingerprint; } set { _fingerprint = value; } }
		
		/// <summary>
		/// Gets or sets the last timestamp the user was authenticated with Google Accounts.
		/// </summary>
		public DateTime LastLoginTime				{ get { return _lastLoginTime; } set { _lastLoginTime = value; } }
		
		/// <summary>
		/// Gets or sets the last timestamp when the mailbox status was refreshed.
		/// </summary>
		public DateTime LastRefreshTime				{ get { return _lastRefreshTime; } set { _lastRefreshTime = value; } }
		
		/// <summary>
		/// Gets or sets the list of new message counts in each of the default searches: Inbox, All, Spam, Starred, Trash, Sent Items.
		/// </summary>
		public SortedList DefaultSearchCounts		{ get { return _defaultSearchCounts; } set { _defaultSearchCounts = value; } }
		
		/// <summary>
		/// Gets or sets the list of new message counts in all the user-defined categories.
		/// </summary>
		public SortedList CategoryCounts			{ get { return _categoryCounts; } set { _categoryCounts = value; } }
		
		/// <summary>
		/// Gets or sets the cookie collection associated with the current session.
		/// </summary>
		public CookieCollection Cookies				{ get { return _cookies; } set { _cookies = value; } }
		
		/// <summary>
		/// Gets or sets the total number of messages in the mailbox.
		/// </summary>
		public int TotalMessages					{ get { return _totalMessages; } set { _totalMessages = value; } }
		
		/// <summary>
		/// Gets or sets the collection of unread threads.
		/// </summary>
		public GmailThreadCollection UnreadThreads	{ get { return _unreadThreads; } set { _unreadThreads = value; } }
		
		/// <summary>
		/// Gets or sets the flag indicating a connection error with Gmail during the last request.
		/// </summary>
		public bool HasConnectionError				{ get { return _hasConnectionError; } set { _hasConnectionError = value; } }

		
		/// <summary>
		/// Initializes a new instance of the GmailSession class.
		/// </summary>
		public GmailSession()
		{
			this._cookies = new CookieCollection();
			
			this._defaultSearchCounts = new SortedList();
			this._defaultSearchCounts["Inbox"] = 0;
			this._defaultSearchCounts["Starred"] = 0;
			this._defaultSearchCounts["All"] = 0;
			this._defaultSearchCounts["Sent"] = 0;
			this._defaultSearchCounts["Spam"] = 0;
			this._defaultSearchCounts["Trash"] = 0;

			this._categoryCounts = new SortedList();
			this._unreadThreads = new GmailThreadCollection();
			this._hasConnectionError = false;

		}

		/// <summary>
		/// Signals the end of the session refresh and raises any appropriate events.
		/// </summary>
		public void FinalizeUpdate() {

			// check to see if there are any new messages; raise NewMessage event.
			if((int)this._defaultSearchCounts["Inbox"] > 0) {
				this.OnNewMessage();
			}
		}


		#region Events (and related components)
		/// <summary>
		/// Default EventHandler for GmailSession events.
		/// </summary>
		public delegate void EventHandler(object sender);

		/// <summary>
		/// Occurs when a new message has been received by the Gmail account.
		/// </summary>
		public event EventHandler NewMessageEventHandler;

		/// <summary>
		/// Occurs when a new message has been received by the Gmail account.
		/// </summary>
		protected virtual void OnNewMessage() {
			if(NewMessageEventHandler != null) {
				NewMessageEventHandler(this);
			}
		}
		#endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Johnvey Hwang
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141030.1 | Last Updated 7 Jul 2004
Article Copyright 2004 by Johnvey Hwang
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid