Looks like you're doing the exact same thing to both flags and attachments. We should make this a bit more DRY. Either split this out into a method, or loop over both lists in one loop using [`itertools.chain`](http://docs.python.org/2/library/itertools.html#itertools.chain)