/*******************************************************************************************
* Project : esdaS©'s OutlookEx Librarie for Basic4PPC *
* DLL-Name: OutlookEx.dll *
* Unit : OutlookEx.cs - Librarie *
* Compiler: Visual Studio 2008 Professional *
* Datum : 09.06.2009 *
* durch : BNG *
* *
* © by Anywhere Software Erel Uziel, Israel - http://www.b4x.com *
* © the expansions by esdaS© - ESPRIT DATA SOFTWARE, Germany - http://www.esdaso.de *
* Author: Bodo-Norbert Göldner - [email protected] *
* *
* ****V3.30.*******************************************************************************/
//ref: Microsoft.WindowsMobile.PocketOutlook.dll
//ref: Microsoft.WindowsMobile.dll
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.WindowsMobile;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using System.Globalization;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
namespace Email
{
public class EmailSender : IDisposable
{
public static OutlookSession session = null;
public double DLLVersion
{
get { return 3.3; }
}
static EmailSender()
{
session = new OutlookSession();
}
public EmailSender()
{
}
public string[] GetAccounts()
{
string[] list = new string[session.EmailAccounts.Count];
int i = 0;
foreach (EmailAccount ea in session.EmailAccounts)
{
list[i] = ea.Name;
i++;
}
return list;
}
public void Send(System.Windows.Forms.Control Form, string Account, object Message)
{
session.EmailAccounts[Account].Send((EmailMessage)Message);
MessagingApplication.Synchronize(Account);
((System.Windows.Forms.Form)Form).Activate();
}
public void Dispose()
{
if (session != null)
session.Dispose();
}
}
public class Message
{
private EmailMessage em = null;
public Message()
{
em = new EmailMessage();
}
public void AddTo(string Address)
{
em.To.Add(new Recipient(Address));
}
public void AddCC(string Address)
{
em.CC.Add(new Recipient(Address));
}
public string BodyText
{
get { return em.BodyText; }
set { em.BodyText = value; }
}
public string Subject
{
get { return em.Subject; }
set { em.Subject = value; }
}
public void AddAttachment(string File)
{
em.Attachments.Add(new Attachment(File));
}
public object Value
{
get { return em; }
set { em = (EmailMessage)value; }
}
}
public class PimCollection
{
PimItemCollection cl;
PropertyDescriptorCollection pc;
CultureInfo cul = new CultureInfo("en-US", false);
public PimCollection(string Type)
{
switch (Type.ToLower())
{
case "contacts":
{
cl = EmailSender.session.Contacts.Items;
pc = TypeDescriptor.GetProperties(typeof(Microsoft.WindowsMobile.PocketOutlook.Contact));
break;
}
case "tasks":
{
cl = EmailSender.session.Tasks.Items;
pc = TypeDescriptor.GetProperties(typeof(Microsoft.WindowsMobile.PocketOutlook.Task));
break;
}
case "appointments":
{
cl = EmailSender.session.Appointments.Items;
pc = TypeDescriptor.GetProperties(typeof(Microsoft.WindowsMobile.PocketOutlook.Appointment));
break;
}
default:
throw new Exception("Type value must be one of the following:\nContacts, Tasks or Appointments.");
}
}
public int Count
{
get { return cl.Count; }
}
public object GetItem(int Index)
{
return cl[Index];
}
public void RemoveItem(int Index)
{
cl.RemoveAt(Index);
}
public void SortItems(string Property, bool Descending)
{
cl.Sort(Property, Descending);
}
public int AddItem(object Item)
{
return cl.Add((PimItem)Item);
}
public int FindItem(string Property, string Value)
{
PropertyDescriptor p = pc.Find(Property, true);
if (p == null)
throw new Exception("Invalid property.");
Type t = p.PropertyType;
if (t == typeof(string))
return cl.Find(p, Value);
else if (t == typeof(DateTime))
{
long l = long.Parse(Value, NumberStyles.Integer, cul);
return cl.Find(p, new DateTime(l));
}
else if (t == typeof(Uri))
{
return cl.Find(p, new Uri(Value));
}
else
return -1;
}
}
public class Contact
{
Microsoft.WindowsMobile.PocketOutlook.Contact ct;
public Contact()
{ }
public object Value
{
get { return ct; }
set { ct = (Microsoft.WindowsMobile.PocketOutlook.Contact)value; }
}
public void CreateNew()
{
ct = new Microsoft.WindowsMobile.PocketOutlook.Contact();
}
public void Update()
{
ct.Update();
}
public Image GetPicture()
{
return ct.Picture;
}
public void SetPicture(string FileName)
{
ct.SetPicture(FileName);
}
public string AccountName { get { return ct.AccountName; } set { ct.AccountName = value; } }
public string AssistantName { get { return ct.AssistantName; } set { ct.AssistantName = value; } }
public long Anniversary { get { return ct.Anniversary.Ticks; } set { ct.Anniversary = new DateTime(value); } }
public long Birthday { get { return ct.Birthday.Ticks; } set { ct.Birthday = new DateTime(value); } }
public string AssistantTelephoneNumber { get { return ct.AssistantTelephoneNumber; } set { ct.AssistantTelephoneNumber = value; } }
public string Body { get { return ct.Body; } set { ct.Body = value; } }
public string BusinessAddressCity { get { return ct.BusinessAddressCity; } set { ct.BusinessAddressCity = value; } }
public string BusinessAddressCountry { get { return ct.BusinessAddressCountry; } set { ct.BusinessAddressCountry = value; } }
public string BusinessAddressPostalCode { get { return ct.BusinessAddressPostalCode; } set { ct.BusinessAddressPostalCode = value; } }
public string BusinessAddressState { get { return ct.BusinessAddressState; } set { ct.BusinessAddressState = value; } }
public string BusinessAddressStreet { get { return ct.BusinessAddressStreet; } set { ct.BusinessAddressStreet = value; } }
public string BusinessFaxNumber { get { return ct.BusinessFaxNumber; } set { ct.BusinessFaxNumber = value; } }
public string BusinessTelephoneNumber { get { return ct.BusinessTelephoneNumber; } set { ct.BusinessTelephoneNumber = value; } }
public string CarTelephoneNumber { get { return ct.CarTelephoneNumber; } set { ct.CarTelephoneNumber = value; } }
public string Categories { get { return ct.Categories; } set { ct.Categories = value; } }
public string Children { get { return ct.Children; } set { ct.Children = value; } }
public string CompanyName { get { return ct.CompanyName; } set { ct.CompanyName = value; } }
public string CompanyTelephoneNumber { get { return ct.CompanyTelephoneNumber; } set { ct.CompanyTelephoneNumber = value; } }
public string Department { get { return ct.Department; } set { ct.Department = value; } }
public string Email1Address { get { return ct.Email1Address; } set { ct.Email1Address = value; } }
public string Email2Address { get { return ct.Email2Address; } set { ct.Email2Address = value; } }
public string Email3Address { get { return ct.Email3Address; } set { ct.Email3Address = value; } }
public string FileAs { get { return ct.FileAs; } set { ct.FileAs = value; } }
public string FirstName { get { return ct.FirstName; } set { ct.FirstName = value; } }
public string GovernmentId { get { return ct.GovernmentId; } set { ct.GovernmentId = value; } }
public string Home2TelephoneNumber { get { return ct.Home2TelephoneNumber; } set { ct.Home2TelephoneNumber = value; } }
public string HomeAddressCity { get { return ct.HomeAddressCity; } set { ct.HomeAddressCity = value; } }
public string HomeAddressCountry { get { return ct.HomeAddressCountry; } set { ct.HomeAddressCountry = value; } }
public string HomeAddressPostalCode { get { return ct.HomeAddressPostalCode; } set { ct.HomeAddressPostalCode = value; } }
public string HomeAddressState { get { return ct.HomeAddressState; } set { ct.HomeAddressState = value; } }
public string HomeAddressStreet { get { return ct.HomeAddressStreet; } set { ct.HomeAddressStreet = value; } }
public string HomeFaxNumber { get { return ct.HomeFaxNumber; } set { ct.HomeFaxNumber = value; } }
public string HomeTelephoneNumber { get { return ct.HomeTelephoneNumber; } set { ct.HomeTelephoneNumber = value; } }
public string IM1Address { get { return ct.IM1Address; } set { ct.IM1Address = value; } }
public string IM2Address { get { return ct.IM2Address; } set { ct.IM2Address = value; } }
public string IM3Address { get { return ct.IM3Address; } set { ct.IM3Address = value; } }
public string JobTitle { get { return ct.JobTitle; } set { ct.JobTitle = value; } }
public string LastName { get { return ct.LastName; } set { ct.LastName = value; } }
public string Manager { get { return ct.Manager; } set { ct.Manager = value; } }
public string MiddleName { get { return ct.MiddleName; } set { ct.MiddleName = value; } }
public string MobileTelephoneNumber { get { return ct.MobileTelephoneNumber; } set { ct.MobileTelephoneNumber = value; } }
public string Ringtone { get { return ct.RingTone; } set { ct.RingTone = value; } }
public string Nickname { get { return ct.Nickname; } set { ct.Nickname = value; } }
public string OfficeLocation { get { return ct.OfficeLocation; } set { ct.OfficeLocation = value; } }
public string PagerNumber { get { return ct.PagerNumber; } set { ct.PagerNumber = value; } }
public string Spouse { get { return ct.Spouse; } set { ct.Spouse = value; } }
public string Suffix { get { return ct.Suffix; } set { ct.Suffix = value; } }
public string Title { get { return ct.Title; } set { ct.Title = value; } }
public string WebPage { get { return ct.WebPage.ToString(); } set { ct.WebPage = new Uri(value); } }
}
public class Task
{
Microsoft.WindowsMobile.PocketOutlook.Task ct;
public Task()
{ }
public object Value
{
get { return ct; }
set { ct = (Microsoft.WindowsMobile.PocketOutlook.Task)value; }
}
public void CreateNew()
{
ct = new Microsoft.WindowsMobile.PocketOutlook.Task();
}
public void Update()
{
ct.Update();
}
public string Body { get { return ct.Body; } set { ct.Body = value; } }
public string Categories { get { return ct.Categories; } set { ct.Categories = value; } }
public string ReminderSoundFile { get { return ct.ReminderSoundFile; } set { ct.ReminderSoundFile = value; } }
public string Subject { get { return ct.Subject; } set { ct.Subject = value; } }
public bool Complete { get { return ct.Complete; } set { ct.Complete = value; } }
public bool ReminderDialog { get { return ct.ReminderDialog; } set { ct.ReminderDialog = value; } }
public bool ReminderLed { get { return ct.ReminderLed; } set { ct.ReminderLed = value; } }
public bool ReminderSet { get { return ct.ReminderSet; } set { ct.ReminderSet = value; } }
public bool ReminderSound { get { return ct.ReminderSound; } set { ct.ReminderSound = value; } }
public bool TeamTask { get { return ct.TeamTask; } set { ct.TeamTask = value; } }
public long DateCompleted { get { return ct.DateCompleted.Ticks; } }
public long DueDate { get { return ct.DueDate.Ticks; } set { ct.DueDate = new DateTime(value); } }
public long StartDate { get { return ct.StartDate.Ticks; } set { ct.StartDate = new DateTime(value); } }
public int Importance { get { return (int)ct.Importance; } set { ct.Importance = (Importance)value; } }
}
public class Appointment
{
Microsoft.WindowsMobile.PocketOutlook.Appointment ct;
public Appointment()
{ }
public object Value
{
get { return ct; }
set { ct = (Microsoft.WindowsMobile.PocketOutlook.Appointment)value; }
}
public void CreateNew()
{
ct = new Microsoft.WindowsMobile.PocketOutlook.Appointment();
}
public void Update()
{
ct.Update();
}
public bool AllDayEvent { get { return ct.AllDayEvent; } set { ct.AllDayEvent = value; } }
public string Body { get { return ct.Body; } set { ct.Body = value; } }
public string Categories { get { return ct.Categories; } set { ct.Categories = value; } }
public int Duration { get { return (int)(ct.Duration.Ticks / TimeSpan.TicksPerMinute); } set { ct.Duration = new TimeSpan(0, value, 0); } }
public long EndTime { get { return ct.End.Ticks; } set { ct.End = new DateTime(value); } }
public bool IsRecurring { get { return ct.IsRecurring; } }
public string Location { get { return ct.Location; } set { ct.Location = value; } }
public bool ReminderDialog { get { return ct.ReminderDialog; } set { ct.ReminderDialog = value; } }
public bool ReminderLed { get { return ct.ReminderLed; } set { ct.ReminderLed = value; } }
public int ReminderMinutesBeforeStart { get { return ct.ReminderMinutesBeforeStart; } set { ct.ReminderMinutesBeforeStart = value; } }
public bool ReminderRepeat { get { return ct.ReminderRepeat; } set { ct.ReminderRepeat = value; } }
public bool ReminderSet { get { return ct.ReminderSet; } set { ct.ReminderSet = value; } }
public bool ReminderSound { get { return ct.ReminderSound; } set { ct.ReminderSound = value; } }
public string ReminderSoundFile { get { return ct.ReminderSoundFile; } set { ct.ReminderSoundFile = value; } }
public bool ReminderVibrate { get { return ct.ReminderVibrate; } set { ct.ReminderVibrate = value; } }
public long Start { get { return ct.Start.Ticks; } set { ct.Start = new DateTime(value); } }
public string Subject { get { return ct.Subject; } set { ct.Subject = value; } }
}
public class SMSMessage
{
private SmsMessage s = null;
public string Body
{
get { return s.Body; }
}
public object Value
{
get { return s; }
set { s = (SmsMessage)value; }
}
public string From
{
get { return s.From.Address; }
}
public long DateReceived
{
get { return s.Received.Ticks; }
}
public SMSMessage(string PhoneNumber, string Text)
{
s = new SmsMessage(PhoneNumber, Text);
s.Send();
}
public SMSMessage()
{ }
}
public class SMSInterceptor : IDisposable
{
private object[] eventObject;
public event EventHandler MessageReceived;
private MessageInterceptor mi = new MessageInterceptor();
public object ReceivedMessage = null;
public SMSInterceptor()
{
eventObject = new object[] { this, "MessageReceived" };
mi.MessageReceived += new MessageInterceptorEventHandler(mi_MessageReceived);
}
void mi_MessageReceived(object sender, MessageInterceptorEventArgs e)
{
if (MessageReceived != null)
{
ReceivedMessage = (SmsMessage)e.Message;
MessageReceived(eventObject, null);
}
}
void IDisposable.Dispose()
{
if (mi != null)
mi.Dispose();
MessageReceived = null;
}
}
}