def METHOD_NAME(self, name, attachments):
    name_counter = Counter([a.name for a in attachments])
    index = 0
    while name_counter[name] > 1:
        index += 1
        path, ext = os.path.splitext(name)
        name = "%s_%d%s" % (path, index, ext)
    return name