python imaplib move message to folder

I am trying to make a script that reads through my email and then downloads attachments if they exist. After the attachments have been downloaded, it needs to move the email to a different folder. I am having troubles moving the e-mail to a different folder though because I keep getting different types of errors when I am selecting the mail. I have checked stackoverflow and other forums but have been unable to come up with a solution that fits my code.

sample code:

import imaplib, email
import os

user = 'email here'
password = 'password here'
imap_url = 'imap url here'
attachment_dir = os.path.join('Attachments')

def auth(user,password,imap_url):
    con = imaplib.IMAP4_SSL(imap_url)
    con.login(user, password)
    return con

def get_attachments(msg):
    for part in msg.walk():
        if part.get_content_maintype() =='multipart':
        if part.get('Content-Disposition') is None:
        fileName = part.get_filename()

        if bool(fileName):
            filePath = os.path.join(attachment_dir, fileName)
            with open(filePath, 'w') as f:

def search(key,value,con):
    result, data =,key,'"{}"'.format(value))
    return data

def get_emails(result_bytes):
    msgs = []
    for num in result_bytes[0].split():
        typ, data = con.fetch(num, '(RFC822)')
    return msgs

con = auth(user, password, imap_url)'INBOX')

msgs = get_emails(search('FROM', 'message sender here', con))

#For message in messages, get attachments & move email to folder
for msg in msgs:
    raw = email.message_from_bytes(msg[0] [1])

    #This is the part where I am trying to move the message to a different folder
    message_id = con.fetch(msg, 'UID')
    result = imaplib.IMAP4.uid('COPY', message_id, 'destination folder here')

I hope someone on here can help me out with moving the emails to a different folder