Tuesday, 15 June 2010

Byte Order mark (BOM) woes

PHP seems to suffer from the BOM problem on windows more than most - here is some code I found that will look through your files and tell you which ones have the evil mark...

http://pastebin.com/dHbqjUNy


define('STR_BOM', "\xEF\xBB\xBF");
$file = null;
$directory = getcwd();

$rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
try {
foreach ($rit as $file) {
if ($file->isFile()) {
$path_parts = pathinfo($file->getRealPath());

if ('php' == $path_parts['extension']) {
$object = new SplFileObject($file->getRealPath());

if (false !== strpos($object->getCurrentLine(), STR_BOM)) {
print $file->getRealPath()."\n";
}
}
}
}

} catch (Exception $e) {
die ('Exception caught: '. $e->getMessage());
}



remember to wrap it in php tags - they are being removed by blogger so i can't show them.

Wednesday, 24 February 2010

retrieve emails as plain text from exchange webservices

basically create a new propertyset with the schema you need to retrieve, and then set the 'RequestedBodyType' of the 'propertyset' to 'BodyType.Text'

code example:

PropertySet myPropertySet = new PropertySet(
ItemSchema.Importance,
ItemSchema.Subject,
ItemSchema.Body,
ItemSchema.DateTimeReceived,
ItemSchema.HasAttachments,
EmailMessageSchema.From,
EmailMessageSchema.ToRecipients,
EmailMessageSchema.DisplayTo

);
myPropertySet.RequestedBodyType = BodyType.Text;
service.LoadPropertiesForItems(findResults.Items, myPropertySet);

foreach (Item myItem in findResults.Items)
{
//etc
}