There are a number of places where mu4e lets you plug in your own functions:
mu4e-compose-pre-hook(see Compose hooks),
You can also write your own functions without using the above. If you want to do so, key
useful functions are
mu4e-message-at-point (see below),
mu4e-headers-for-each (to iterate over all headers, see its docstring) and
mu4e-view-for-each-part (to iterate over all parts/attachments, see its docstring).
There is also
mu4e-view-for-each-uri to iterate of all the URIs in the current
Another useful function is
mu4e-headers-find-if which searches for a message
matching a certain pattern; again, see its docstring.