You probably need to put this all the way at the end even after adding the attachments as the get_user function also tries to login as said user.

Will need to check the code further... might even need to patch get_user to suppress login part of that function. If that is suppressed this line can stay where it is now