This question is closely related to How can I right-align a quotation attribution, on the same line as the quotation if possible?
I am currently using the TeXBook's excellent solution, among those described in that question, except for a minor change in spacing (a 1em gap between the quotation and the attribution instead of 2em):
\def\attr#1{{\unskip\nobreak\hfil\penalty50
\hskip1em\hbox{}\nobreak\hfil\itshape---#1
\parfillskip=0pt \finalhyphendemerits=0 \par}}
However, an additional problem has arisen: I am setting this text in two columns, and some attributions end up breaking onto multiple lines. This tends to look silly right-aligned:
In general, I would much rather have the attribution begin left-aligned on a new line, should it require more than one line:
I need an automated solution because I'm generating the text programmatically. I will be doing some manual tweaking afterwards, but as I'm typesetting over 10,000 of these entries, anything that can be done to get most of them right automatically is a huge time-saver.



