code: def get_sorted_attachments(self):
          inf = float("inf")
          order = self.get_attachments_order()
          attachments = self.get_attachments()
          def att_cmp(att1, att2):
              _n1 = att1.get('UID')
              _n2 = att2.get('UID')
              _i1 = _n1 in order and order.index(_n1) + 1 or inf
              _i2 = _n2 in order and order.index(_n2) + 1 or inf
              return cmp(_i1, _i2)
          sorted_attachments = sorted(attachments, cmp=att_cmp)
          return sorted_attachments