import java.util.Map;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;


public class EmailToSqlProcessor implements Processor {

	@Override
	public void process(Exchange arg0) throws Exception {
		Map<String,Object> headers = arg0.getIn().getHeaders();
		for(String s : headers.keySet())
			System.out.println(s + " " + headers.get(s).toString() + "\n");
		Message out = arg0.getIn().copy();
		
		out.setHeader("Action", headers.get("Subject"));
		out.setBody("");
		
		String email = headers.get("From").toString();
		String body = "";
		
		body +="Insert into subscriber (email) values ('" + email +"');\n";
		
		for(String s : arg0.getIn().getBody().toString().split("\n"))
		{
			if(s.startsWith("Location:"))
				body +="Insert into locations (email, location) values ('" + email +"','" + s.split(":")[1] + "');\n";
			if(s.startsWith("Artist:"))
				body +="Insert into subscriptions (email, artist) values ('" + email +"','" + s.split(":")[1] + "');\n";
		}

		out.setBody(body);
		arg0.setOut(out);
	}

}

@@ -14,16 +14,80 @@
 til.Map;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -629,16 +629,152 @@
 ring();%0A
+%09%09%0A%09%09Matcher m = Pattern.compile(%22%5Ba-zA-Z0-9_.+-%5D+@%5Ba-zA-Z0-9-%5D+%5C%5C.%5Ba-zA-Z0-9-.%5D+%22).matcher(email);%0A%09%09m.find();%0A%09%09email = m.group();%0A%09%09%0A
 %09%09String

properly extracting email addresses