This can only be tested with unit tests, as we don't use the $attachment and $attachname params in core.
Comment out the change to lib/moodlelib.php introduced with this patch.
Run the moodlelib_test.php unit tests.
Confirm that the test_email_to_user test fails.
Uncomment the line from step 1.
Run the moodlelib_test.php unit tests.
Confirm that the test_email_to_user test passes.
Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)