Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

tim

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

extract email addresses

<?php

function extract_emails_from($string){
  preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
  return $matches[0];
}

$text = "blah blah blah [email protected] blah blah blah [email protected]";

$emails = extract_emails_from($text);

print(implode("\n", $emails));

?>


Context: http://forum.textdrive.com/viewtopic.php?pid=46783

rip calendar attachments from an email

See here for context.

#!/usr/bin/env /usr/local/bin/python

import sys, email

msg = email.message_from_string(sys.stdin.read())

for part in msg.walk():
  if part.get_content_type() == 'text/calendar':
    f = open(part.get_filename(), 'w')
    f.write(part.get_payload())
    f.close()
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed