What is the mechanism by which magnetic fields do work? I've seen some conflicted answers to this question in texts and on the web, in the case of a dipole, for example. 
Do magnetic fields do work directly, or is it their induced electric fields that do work?
 A: As Emilio Pisanty asserts, the magnetic Lorentz force $\boldsymbol{F_m}= q \boldsymbol{v \times B }$ does not do work, since $\boldsymbol{F_m \cdot v} = 0$.  I don't have access to Griffith, but I find Feynman's discussion (in v. II, ch 15) confusing, since he has magnetic forces doing work on the current while also asserting those same forces do no work.
To see what's going on (classically, at least) consider an ideal, zero-resistance, wire driven by a current source $I$ in a magnetic field $\boldsymbol{B}$.  The current $I$ is carried by mobile electrons whose negative charge $q_e<0$ is balanced by a fixed lattice of (much more massive) positively charged wire ions $q_w>0$, with $q_w=-q_e$ for simplicity.
The wire's moving current-carrying electrons (average velocity $\boldsymbol{v_e}$) will be deflected by the Lorentz force $\boldsymbol{F_e} = q_e (\boldsymbol{v_e \times B})$. Consequently, the electrons will tend to "pile-up" on one side of the wire.  The wire's net charge density is now no longer zero, so an electric field $\boldsymbol{E}$ is produced that opposes the deflection.  In steady-state, the electric force must just balance the Lorentz force, so the net force on the electrons vanishes:
$$ \boldsymbol{E} = - (\boldsymbol{v_e \times B}) $$ 
(This is just the Hall effect.)
Now this electric field will accelerate the wire's ions, since there is no counteracting magnetic force on them.  In fact, the electric force on the wire ions $\boldsymbol{F_w}$ is exactly equal to the magnetic force $\boldsymbol{F_e}$ on the electrons:
$$ \boldsymbol{F_w} = q_w \boldsymbol{E} = - q_e \boldsymbol{E} = q_e (\boldsymbol{v_e \times B}) = \boldsymbol{F_e} $$
The key difference is that this electric force can and will do work on the lattice.

If the wire is initially motionless ($\boldsymbol{v_w}=0$), the average electron velocity $\boldsymbol{v_e}=\boldsymbol{v_c}$, where $\boldsymbol{v_c}$ is parallel to the wire (increment $ \boldsymbol{dl}$) and
$$|q_e| \, n A_c \, |v_c|=I$$
(with $n$ the electron density and $A_c$ the wire cross-sectional area),
Then $\boldsymbol{E=-v_e \times B}$ is perpendicular to $d \boldsymbol{l}$, and the line integral of $\boldsymbol{E}$ around the wire is 0, so the applied voltage is 0 and the current source provides no power to the wire.  But that's not surprising, since the rate of mechanical work being done on each lattice ion is $\boldsymbol{F_w \cdot v_w}=0$ also.

For a non-zero wire velocity $\boldsymbol{v_w}$, the electron velocity $\boldsymbol{v_e}=\boldsymbol{v_c}+\boldsymbol{v_w}$, and there will be a non-zero component of $\boldsymbol{E}$ along $ \boldsymbol{dl}$:
$$\boldsymbol{E} \cdot \boldsymbol{dl} = - (\boldsymbol{v_e \times B}) \boldsymbol{\cdot} \boldsymbol{dl} = - (\boldsymbol{v_w \times B}) \boldsymbol{\cdot} \boldsymbol{dl} $$
so the electrical power $P_e$ supplied by the current source is:
$$ P_e = VI = I \int -\boldsymbol{E \cdot dl} = I \int \boldsymbol{( v_w \times B ) \cdot dl} $$
The mechanical power $P_m$ applied to the wire is the sum of the individual ion powers:
$$ P_m = \sum  \boldsymbol{F_w \cdot v_w} = q_m n \int \boldsymbol{E \cdot v_w} \, dV = - q_m n \int \boldsymbol{(v_e \times B) \cdot v_w} \, dV $$
By a vector identity, and since $ \boldsymbol{v_e = v_c + v_w} $ and $q_m = -q_e$,
$$ P_m = - q_m n \int \boldsymbol{( B \times v_w) \cdot v_e} \, dV = q_m n \int \boldsymbol{( v_w \times B ) \cdot v_c} \, dV =  I \int \boldsymbol{( v_w \times B ) \cdot dl}$$
for a thin wire, and $ P_m =  P_e $.
A: Magnetic fields never do work directly on electric charges. This is because the magnetic force on any charged particle,
$$\mathbf{F}=q\mathbf{v}\times \mathbf{B,}$$
is always orthogonal to the velocity, and therefore the power transferred, $\mathbf{F}\cdot\mathbf{v}$, is zero.
On the other hand, this seems to contradict much of our intuition about how magnets behave. If you take two magnets and put them close to each other, they will snap together, accelerating in the process, so there's definitely something that's doing work. What that something is will usually depend on what frame of reference you're working in.
The standard example is a loop of wire moving relative to a magnet, which induces a current in it. If you consider the situation in the frame where the loop is stationary, then what you see is a changing magnetic field; by Faraday's law this means there's an induced electric field that accelerates charges around the loop. On the other hand, in the magnet's frame of reference there are only magnetic fields, so it must be something else, which turns out to be the motion of the loop. 
Assume for simplicity that the loop is travelling along its normal $\mathbf{n}$. Then the charges have a velocity $\mathbf{v}\propto\mathbf{n}$, and the magnetic force will give them an impulse perpendicular to that and thus along the loop. Once you have such a current going, though, the velocity of the charges has a component that's orthogonal to $\mathbf{n}$, and this will also incur in a magnetic force, which will now be along $\mathbf{n}$ and tending to slow the loop down. You will therefore create a current at the expense of the loop's kinetic energy or out of the work performed by some extra force that's keeping the velocity constant. There is a nice in-depth explanation of this example in Griffith's Introduction to electrodynamics (example 5.3, section 5.1; p. 209 in the 3rd edition).
The attracting magnets can be treated in a somewhat similar fashion. For one, you can swap the permanent magnets for loops of current without loss of generality, because the magnetic fields they produce are actually produced by magnetization currents on their surface. Put them close enough, and you get to the core of the problem, the magnetic force between two current-carrying wires.
Consider, then, two parallel wires carrying currents in the same direction, so that they attract and move towards each other. Again, in the frame of reference of each moving wire there's an electric field induced by a changing magnetic field, and this can perform work. In the lab frame, on the other hand, you have each wire moving in the magnetic field of the other. Once they're moving towards each other, the charges in each wire have a velocity component along the wire and one along the separation vector. The second component will incur a magnetic force on the charge carriers that's against the current direction; this means that you need a current source to keep it steady (with the associated energy cost) or the current in the wires will decrease.
For the magnets, then, this means that the magnetization of two magnets that snap together will actually decrease slightly in the process, by a specific mechanism which depends on where that magnetization comes from. This is, by the way, in principle, a temporary thing: the work you perform on the magnets when you prize them apart goes, essentially, into re-establishing the magnetization.

One should note, on the other hand, that strictly speaking this applies only to charged particles and, by extension, to systems that are made up of charged particles. It does not, however, cover the case of point dipoles, such as electrons, for which the fundamental force (and torque) exerted by a magnetic field are different, and given by
$$
\mathbf F=\nabla(\boldsymbol \mu·\mathbf B)
\quad\text{and}\quad
\boldsymbol\tau=\boldsymbol \mu\times\mathbf B
.$$
This leaves permanent magnets in a bit of a funny position, because they are fundamentally made up of aligned electron spins so one should in principle apply to that description.
However, in a useful description of a permanent magnet you take a macroscopic average of the local magnetic dipole density to obtain its magnetization $\mathbf M$, and in the process you cease to care where the magnetization comes from. As far as classical electrodynamics is concerned (and unless you want to meddle with individual atoms inside it), a permanent magnet is simply a material with a permanent magnetization $\mathbf M$, all of whose interactions with other charges and currents occur via its bulk and surface magnetization currents,
$$
\mathbf J=\nabla\times\mathbf M
\quad\text{and}\quad
\mathbf K=\mathbf M \times\hat{\mathbf n}
.$$
If the magnetization is uniform then there is no bulk current density (each bulk dipole 'cancels out' with its neighbours) and the magnetization current is confined to the surface. Thus, a uniformly-magnetized bar of iron is well modelled by magnetization currents on its surface, and the magnetic-work paradox can also be resolved as above - by the action of an induced electric field, or by magnetic forces slowing down those currents once there is motion along the loop normal.
In the end, the difference between the two is a bit of a personal-choice thing. It is generally somewhat harder to handle point dipoles and there are in general few situations that cannot be modelled by using electric currents, so it is a good thing to keep those models, and their counter-intuitive properties, well in mind. On the other hand, it is probably true that physics could do a bit of a better job remembering to emphasize that magnetic fields never do work directly on electric charges.
A: It depends. The general rule is that:

*

*(non-uniform) Magnetic fields can do work on intrinsic dipoles, such as the spin of an electron. Indeed in the Stern-Gerlach experiment particles are being accelerated by a non-uniform magnetic field. In such cases the force is $\textbf{F}=\nabla (\textbf{m} \cdot \textbf{B})$ where $\textbf{m}$ is the magnetic dipole moment of the intrinsic dipole, and $\textbf{B}$ is the field it is immersed it. Note that this is clearly a conservative force field, and hence we may define a potential energy $U=-\textbf{m}\cdot \textbf{B}$.


*Magnetic fields in general however cannot do work on systems comprising of currents. In such cases the force on the currents is always the Lorentz force, which coincidentally for a "physical" dipole, one with an associated current, turns out to still be $\textbf{F}=\nabla(\textbf{m}\cdot \textbf{B})$. In this case however the force is perpendicular to the velocity of the particles, hence no work is being done. Intrinsic dipoles are exempted from this because they do not, by definition, have an associated physical current to them.
Hence when two magnets attract, because most of their "magnetism" comes from the intrinsic dipole moment (spin) of electrons, the magnetic field is doing work indeed. This nice paper shows that the decrease in the magnetic field energy when two magnets snap together is paid back by an increase in kinetic energy https://www.physics.princeton.edu/~mcdonald/examples/mag_energy.pdf.
However, when two electromagnets attract, then the magnetic field is doing no work. Let us model the two electromagnets as two loops carrying current $I_a$ and $I_b$, with self-inductances $L_a$ and $L_b$, and mutual inductance $M$. Assume that the upper loop with current $I_b$ is fixed, and that only the lower loop with current $I_a$ moves.
As the diagram below shows, the initial magnetic force will be upwards, perpendicular to the current. No work is being done. Since the charge carriers are constrained to move in the wire, they will exert a force (not magnetic in nature) on the wire. Hence the wire will start moving upwards.

Now the instant the wire starts moving upwards, the charges will also gain a velocity component $\textbf{v}^\perp$ perpendicular to their original motion. This component will produce a horizontal component $\textbf{F}_{mag}^\perp$ of the magnetic force opposing the flow of current. In the absence of a source then, the currents will decrease, and the work done by the magnetic field in doing so will precisely balance out the work done by the horizontal component in raising the ring. Hence the magnetic field will have done no work, and of course we see this visually because the total force $\textbf{F}_{mag}$ is indeed perpendicular to the total velocity $\textbf{v}$.

Let's prove this result. The magnetic fluxes through the two loops are:
\begin{align}
    &\Phi_a = L_a I_a + MI_b\\
    &\Phi_b = L_b I_b + MI_a
\end{align}
which induce emfs in the loops opposing flow of current:
\begin{align}
    &\varepsilon_a = -L_a \frac{dI_a}{dt} - \frac{dM}{dt}I_b - M\frac{dI_b}{dt}\\
    &\varepsilon_b = -L_b \frac{dI_b}{dt} - \frac{dM}{dt}I_a - M\frac{dI_a}{dt}
\end{align}
So in the absence of an external supply of energy we will find that the currents decrease. The rate at which work is done by these emfs is then:
\begin{align}
    &\frac{dW_a}{dt} = -L_a\frac{dI_a}{dt}I_a - \frac{dM}{dt}I_bI_a - M\frac{dI_b}{dt}I_a\\
    &\frac{dW_b}{dt} = -L_b\frac{dI_b}{dt}I_b - \frac{dM}{dt}I_bI_a - M\frac{dI_a}{dt}I_b
\end{align}
Note that the work $dW_b$ is totally due to induced electric fields, the emf comes from Faraday's law. Instead, the work $dW_a$ is partly a faraday emf due to the changing magnetic fields of the two loops (the term $-L_a\frac{dI_a}{dt}I_a- M\frac{dI_b}{dt}I_a$) and partly a motional emf $-\frac{dM}{dt}I_bI_a$ which is done by the horizontal component of the magnetic force. The total work done by the emfs is:
\begin{equation}
    \frac{dW_a}{dt}+\frac{dW_b}{dt} = -L_a\frac{dI_a}{dt}I_a-L_b\frac{dI_b}{dt}I_b-2\frac{dM}{dt} I_a I_b - MI_b \frac{dI_a}{dt} + MI_a \frac{dI_b}{dt}
\end{equation}
Meanwhile, the change in the field energy is:
\begin{align}
    &U = \frac{1}{2}L_aI_a^2 + \frac{1}{2}L_bI_b^2 + MI_aI_b\\
    &\frac{dU}{dt} = L_a I_a \frac{dI_a}{dt} + L_a I_b \frac{dI_b}{dt} + MI_b \frac{dI_a}{dt} + MI_a \frac{dI_b}{dt} + \frac{dM}{dt} I_a I_b
\end{align}
Hence we may write that
\begin{equation}\tag{*}\label{energy cons}
    \frac{dU}{dt} + I_aI_b\frac{dM}{dt} = -\bigg(\frac{dW_a}{dt}+\frac{dW_b}{dt}\bigg)
\end{equation}
We now recognise the work $W_g$ done in lifting the loop in $\eqref{energy cons}$:
\begin{equation}
    \frac{dW_g}{dt} = I_aI_b \frac{dM}{dt}
\end{equation}
so that:
\begin{equation}\tag{**}\label{energy cons2}
    \frac{dU}{dt} + \frac{dW_g}{dt} = -\bigg(\frac{dW_a}{dt}+\frac{dW_b}{dt}\bigg)
\end{equation}
We may also rewrite $\eqref{energy cons2}$ in the energy conservation form:
\begin{equation}
    U + W_g + W_a + W_b = \text{cnst.}
\end{equation}
So in the absence of a source the work done by the emfs (be it faraday or motional) in reducing the currents is paid back by a change in potential energy and translational kinetic energy (given by $W_g$ using the work-energy theorem).
Note that the work done by the magnetic field's vertical component on the loop is only the $-I_aI_b\frac{dM}{dt}$ term in $dW_a$ which is incidentally the negative of the work done by the horizontal component $dW_g$. Hence, as required, the magnetic field does no work. The faraday emfs in $W_a$ and $W_b$ instead are responsible for the change in field energy $U$. What force was responsible for the loop being lifted? The vertical component $\textbf{F}_{mag}^\parallel$ of the magnetic force, of course, but did the magnetic force do work overall? Of course not.
The magnetic field also does no work on loop b, as the emf there is purely faraday. Hence the work is done by an induced electric field rather than a magnetic field.
