Index: cleanup/mms_us_metropcs/README.txt =================================================================== RCS file: cleanup/mms_us_metropcs/README.txt diff -N cleanup/README.txt --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cleanup/README.txt 3 Mar 2009 00:25:18 -0000 @@ -0,0 +1,24 @@ +; $Id$ + +mms_us_metropcs +--------------- +This is a prototype module to try and clean up messages that are posted via +the MMS feature of a mobile phone. The emails generated this way typically +contain additional logos from the service provider, and possible additional +text. + +hook_mailsave_clean is triggered by mailsave before it calls hook_mailsave. +You can therefore intercept the node and the email attachments before +other modules begin processing. + +By implementing hook_mailsave_clean in a module you can therefore discard +additional images that are attached and modify the text of the node. + +hook_mailsave_clean passes the node, but also information about the mailbox +and the email that is currently in use. + +-------- + +MetroPCS messages are identified by being from @mymetropcs.com. The +messages are plain text, but have a long string attached to the end +which is stripped. There are no additional attachments to remove. Index: cleanup/mms_us_metropcs.inc =================================================================== RCS file: cleanup/mms_us_metropcs.inc diff -N cleanup/mms_us_metropcs.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ cleanup/mms_us_metropcs.inc 3 Mar 2009 00:25:18 -0000 @@ -0,0 +1,74 @@ +fromaddress)) { + + // Build a regex to extract message body + // This regex identifies the actual message text in the email + $end_pattern = preg_quote('This message was sent using picture-talk messaging service from MetroPCS.'); + $pattern = '@^(.*)' . $end_pattern . '@Us'; + + // Check for regex success in case the provider changes their format + // Worst case is that match fails and nothing is changed + if (preg_match($pattern, $node->body)) { + + // Find the HTML element containing user-supplied text. + preg_match_all('!(.*?)!s', $node->body, $matches); + // Get the new body as a string + $body = $matches[1][1]; + + // Store the amended body + $node->body = $body; + $node->teaser = node_teaser($node->body); + + // Set node title and reset the body if the author just puts short text in the body + if (empty($node->title) && !empty($node->body) && strlen($node->body) <= 60) { + $node->title = truncate_utf8($body, 60, TRUE, TRUE); + $node->body = ''; + } + + // If there is no title and a long body, use body to set the title + if (empty($node->title) && !empty($node->body)) { + $node->title = truncate_utf8($body, 60, TRUE, TRUE); + } + + // If there is no title and no body, create a generic title + // Maybe this needs to be generic in mailsave or mailsave_to_image? + if (empty($node->title) && empty($node->body)) { + $node->title = t('Mobile Submission'); + } + + // Get rid of extra text attachments + foreach ($node->mailsave_attachments as $key => $file) { + if ($file['filemime'] == 'text/plain') { + unset($node->mailsave_attachments[$key]); + } + } + + } + } + + return; +} + + +/** + * Report back module information when requested + */ +function mms_us_metropcs_mailsave_clean_info() { + $items['mms_us_metropcs'] = array( + 'provider' => t('MetroPCS'), + 'country' => 'US', + 'author' => 'Stuart Greenfield', + 'description' => t('Clean up MMS messages sent via the MetroPCS US network.'), + ); + + return $items; +}