public static String GetStringProperty(MapiGuts.MAPIProp obj, Tags propId) { //Helper to get a single string property from a MAPI object Value val = MapiUtils.GetProperty(obj, propId); if (val != null) { return val.ToString(); } else { return null; } }
public static DateTime GetAppTimeProperty(MapiGuts.MAPIProp obj, Tags propId) { Value val = MapiUtils.GetProperty(obj, propId); if (val != null) { return ((MapiAppTime)val).Value; } else { return DateTime.MinValue; } }
public static Value GetProperty(MapiGuts.MAPIProp obj, Tags propId) { //Helper to get a single property from a MAPI object Tags[] propIds = new Tags[] {propId}; Value[] values; try { Error hr = obj.GetProps(propIds, 0, out values); if (hr != Error.Success) { if (hr == Error.ErrorsReturned) { //There was an error getting the property. The error code is returned instead uint error = (uint)((MapiError)values[0]).Value; if (error == MapiException.MAPI_E_NOT_FOUND) { //Property not found return null; } throw new MapiException(error); } throw new MapiException(hr); } return values[0]; } catch (Exception e) { return new MapiString(Tags.PR_DISPLAY_NAME, String.Format("Exception: {0}", e.Message)); } }
public static String GetLongStringProperty(MapiGuts.MAPIProp obj, Tags propId) { //Gets a string that is potentially long, and therefore must be retrieved //using a stream. IUnknown unk; Error hr = obj.OpenProperty(propId, IStream.IID, 0, 0, out unk); if (hr == Error.Success) { using (unk) { IStream stream = (IStream)unk; using (stream) { using (MemoryStream properyContents = new MemoryStream()) { byte[] buffer = new byte[1024]; int read = 0; do { hr = stream.Read(buffer, (uint)buffer.Length, out read); properyContents.Write(buffer, 0, read); } while (hr == Error.Success && read > 0); //Seek back to the start of the stream, and read it as text properyContents.Seek(0, SeekOrigin.Begin); //UTF-8 seems reasonable, at least for my email. using (StreamReader rdr = new StreamReader(properyContents, System.Text.Encoding.UTF8)) { return rdr.ReadToEnd(); } } } } } return String.Format("Error getting {0}: {1:X}", propId, hr); }
public static int GetLongProperty(MapiGuts.MAPIProp obj, Tags propId) { Value val = MapiUtils.GetProperty(obj, propId); if (val != null) { return ((MapiInt32)val).Value; } else { return Int32.MinValue; } }
public static ENTRYID GetEntryIdProperty(MapiGuts.MAPIProp obj, Tags propId) { //Helper to get a single Entry ID property from a MAPI object Value val = MapiUtils.GetProperty(obj, propId); if (val != null) { return ENTRYID.Create(val); } else { return null; } }
public static byte[] GetBinaryProperty(MapiGuts.MAPIProp obj, Tags propId) { //Helper to get a single string property from a MAPI object Value val = MapiUtils.GetProperty(obj, propId); if (val != null) { return ((MapiBinary)val).Value; } else { return null; } }