MDL-12990 - clean up message_print_contacts() a lot to:  * Use less DB queries and avoid getting lots of needless data  * Dont do a big php array rearranging loop - database does the work for us instead  * split all the duplicated display code into a single function
MDL-12990 - clean up message_print_contacts() a lot to:
 * Use less DB queries and avoid getting lots of needless data
 * Dont do a big php array rearranging loop - database does the work for us instead
 * split all the duplicated display code into a single function

merged from MOODLE_19_STABLE

dilawar/moodle