prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ImportError: Module import failed for IMAP Folder
  Migrating from latest `version-13` to `develop`:
  
  ```
  > bench --site my-site migrate
  Migrating my-site
  Executing frappe.patches.v14_0.copy_mail_data #08.03.21 in my-site (_f0159c4c37bf09c0)
  
  Traceback (most recent call last):
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 202, in load_doctype_module
      doctype_python_modules[key] = frappe.get_module(module_name)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 987, in get_module
      return importlib.import_module(modulename)
    File "/home/frappe/frappe-bench/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  ModuleNotFoundError: No module named 'frappe.core.doctype.imap_folder'
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 104, in <module>
      main()
    File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
      click.Group(commands=commands)(prog_name='bench')
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
      return self.main(*args, **kwargs)
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 782, in main
      rv = self.invoke(ctx)
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
      return ctx.invoke(self.callback, **ctx.params)
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
      return callback(*args, **kwargs)
    File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
      return f(get_current_context(), *args, **kwargs)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 26, in _func
      ret = f(frappe._dict(ctx.obj), *args, **kwargs)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 460, in migrate
      skip_search_index=skip_search_index
    File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 68, in migrate
      frappe.modules.patch_handler.run_all(skip_failing)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 36, in run_all
      run_patch(patch)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 25, in run_patch
      if not run_single(patchmodule = patch):
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 66, in run_single
      return execute_patch(patchmodule, method, methodargs)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 86, in execute_patch
      frappe.get_attr(patchmodule.split()[0] + ".execute")()
    File "/home/frappe/frappe-bench/apps/frappe/frappe/patches/v14_0/copy_mail_data.py", line 19, in execute
      "uidnext": doc.uidnext,
    File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 183, in append
      value = self._init_child(value, key)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 222, in _init_child
      value = get_controller(value["doctype"])(value)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 70, in get_controller
      site_controllers[doctype] = _get_controller()
    File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 52, in _get_controller
      module = load_doctype_module(doctype, module_name)
    File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py", line 204, in load_doctype_module
      raise ImportError('Module import failed for {0} ({1})'.format(doctype, module_name + ' Error: ' + str(e)))
  ImportError: Module import failed for IMAP Folder (frappe.core.doctype.imap_folder.imap_folder Error: No module named 'frappe.core.doctype.imap_folder')
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `frappe/patches/v14_0/copy_mail_data.py`
  Content:
  ```
  1 from __future__ import unicode_literals
  2 import frappe
  3 
  4 
  5 def execute():
  6 	frappe.reload_doc("email", "doctype", "email_account")
  7 	# patch for all Email Account with the flag use_imap
  8 	for email_account in frappe.get_list("Email Account", filters={"enable_incoming": 1, "use_imap": 1}):
  9 		# get all data from Email Account
  10 		doc = frappe.get_doc("Email Account", email_account.name)
  11 
  12 		imap_list = [folder.folder_name for folder in doc.imap_folder]
  13 		# and append the old data to the child table
  14 		if doc.uidvalidity or doc.uidnext and "INBOX" not in imap_list:
  15 			doc.append("imap_folder", {
  16 				"folder_name": "INBOX",
  17 				"append_to": doc.append_to,
  18 				"uid_validity": doc.uidvalidity,
  19 				"uidnext": doc.uidnext,
  20 			})
  21 
  22 			doc.save()
  23
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/frappe/patches/v14_0/copy_mail_data.py b/frappe/patches/v14_0/copy_mail_data.py
  --- a/frappe/patches/v14_0/copy_mail_data.py
  +++ b/frappe/patches/v14_0/copy_mail_data.py
  @@ -3,7 +3,9 @@
   
   
   def execute():
  +	frappe.reload_doc("email", "doctype", "imap_folder")
   	frappe.reload_doc("email", "doctype", "email_account")
  +
   	# patch for all Email Account with the flag use_imap
   	for email_account in frappe.get_list("Email Account", filters={"enable_incoming": 1, "use_imap": 1}):
   		# get all data from Email Account
  
verification_info: {"golden_diff": "diff --git a/frappe/patches/v14_0/copy_mail_data.py b/frappe/patches/v14_0/copy_mail_data.py\n--- a/frappe/patches/v14_0/copy_mail_data.py\n+++ b/frappe/patches/v14_0/copy_mail_data.py\n@@ -3,7 +3,9 @@\n \n \n def execute():\n+\tfrappe.reload_doc(\"email\", \"doctype\", \"imap_folder\")\n \tfrappe.reload_doc(\"email\", \"doctype\", \"email_account\")\n+\n \t# patch for all Email Account with the flag use_imap\n \tfor email_account in frappe.get_list(\"Email Account\", filters={\"enable_incoming\": 1, \"use_imap\": 1}):\n \t\t# get all data from Email Account\n", "issue": "ImportError: Module import failed for IMAP Folder\nMigrating from latest `version-13` to `develop`:\r\n\r\n```\r\n> bench --site my-site migrate\r\nMigrating my-site\r\nExecuting frappe.patches.v14_0.copy_mail_data #08.03.21 in my-site (_f0159c4c37bf09c0)\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py\", line 202, in load_doctype_module\r\n    doctype_python_modules[key] = frappe.get_module(module_name)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py\", line 987, in get_module\r\n    return importlib.import_module(modulename)\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/importlib/__init__.py\", line 126, in import_module\r\n    return _bootstrap._gcd_import(name[level:], package, level)\r\n  File \"<frozen importlib._bootstrap>\", line 994, in _gcd_import\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 941, in _find_and_load_unlocked\r\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\r\n  File \"<frozen importlib._bootstrap>\", line 994, in _gcd_import\r\n  File \"<frozen importlib._bootstrap>\", line 971, in _find_and_load\r\n  File \"<frozen importlib._bootstrap>\", line 953, in _find_and_load_unlocked\r\nModuleNotFoundError: No module named 'frappe.core.doctype.imap_folder'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.6/runpy.py\", line 193, in _run_module_as_main\r\n    \"__main__\", mod_spec)\r\n  File \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py\", line 104, in <module>\r\n    main()\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py\", line 18, in main\r\n    click.Group(commands=commands)(prog_name='bench')\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 829, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 782, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 1259, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 1259, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 1066, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/core.py\", line 610, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"/home/frappe/frappe-bench/env/lib/python3.6/site-packages/click/decorators.py\", line 21, in new_func\r\n    return f(get_current_context(), *args, **kwargs)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py\", line 26, in _func\r\n    ret = f(frappe._dict(ctx.obj), *args, **kwargs)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py\", line 460, in migrate\r\n    skip_search_index=skip_search_index\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py\", line 68, in migrate\r\n    frappe.modules.patch_handler.run_all(skip_failing)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py\", line 36, in run_all\r\n    run_patch(patch)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py\", line 25, in run_patch\r\n    if not run_single(patchmodule = patch):\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py\", line 66, in run_single\r\n    return execute_patch(patchmodule, method, methodargs)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py\", line 86, in execute_patch\r\n    frappe.get_attr(patchmodule.split()[0] + \".execute\")()\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/patches/v14_0/copy_mail_data.py\", line 19, in execute\r\n    \"uidnext\": doc.uidnext,\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py\", line 183, in append\r\n    value = self._init_child(value, key)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py\", line 222, in _init_child\r\n    value = get_controller(value[\"doctype\"])(value)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py\", line 70, in get_controller\r\n    site_controllers[doctype] = _get_controller()\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py\", line 52, in _get_controller\r\n    module = load_doctype_module(doctype, module_name)\r\n  File \"/home/frappe/frappe-bench/apps/frappe/frappe/modules/utils.py\", line 204, in load_doctype_module\r\n    raise ImportError('Module import failed for {0} ({1})'.format(doctype, module_name + ' Error: ' + str(e)))\r\nImportError: Module import failed for IMAP Folder (frappe.core.doctype.imap_folder.imap_folder Error: No module named 'frappe.core.doctype.imap_folder')\r\n```\n", "before_files": [{"content": "from __future__ import unicode_literals\nimport frappe\n\n\ndef execute():\n\tfrappe.reload_doc(\"email\", \"doctype\", \"email_account\")\n\t# patch for all Email Account with the flag use_imap\n\tfor email_account in frappe.get_list(\"Email Account\", filters={\"enable_incoming\": 1, \"use_imap\": 1}):\n\t\t# get all data from Email Account\n\t\tdoc = frappe.get_doc(\"Email Account\", email_account.name)\n\n\t\timap_list = [folder.folder_name for folder in doc.imap_folder]\n\t\t# and append the old data to the child table\n\t\tif doc.uidvalidity or doc.uidnext and \"INBOX\" not in imap_list:\n\t\t\tdoc.append(\"imap_folder\", {\n\t\t\t\t\"folder_name\": \"INBOX\",\n\t\t\t\t\"append_to\": doc.append_to,\n\t\t\t\t\"uid_validity\": doc.uidvalidity,\n\t\t\t\t\"uidnext\": doc.uidnext,\n\t\t\t})\n\n\t\t\tdoc.save()\n", "path": "frappe/patches/v14_0/copy_mail_data.py"}], "after_files": [{"content": "from __future__ import unicode_literals\nimport frappe\n\n\ndef execute():\n\tfrappe.reload_doc(\"email\", \"doctype\", \"imap_folder\")\n\tfrappe.reload_doc(\"email\", \"doctype\", \"email_account\")\n\n\t# patch for all Email Account with the flag use_imap\n\tfor email_account in frappe.get_list(\"Email Account\", filters={\"enable_incoming\": 1, \"use_imap\": 1}):\n\t\t# get all data from Email Account\n\t\tdoc = frappe.get_doc(\"Email Account\", email_account.name)\n\n\t\timap_list = [folder.folder_name for folder in doc.imap_folder]\n\t\t# and append the old data to the child table\n\t\tif doc.uidvalidity or doc.uidnext and \"INBOX\" not in imap_list:\n\t\t\tdoc.append(\"imap_folder\", {\n\t\t\t\t\"folder_name\": \"INBOX\",\n\t\t\t\t\"append_to\": doc.append_to,\n\t\t\t\t\"uid_validity\": doc.uidvalidity,\n\t\t\t\t\"uidnext\": doc.uidnext,\n\t\t\t})\n\n\t\t\tdoc.save()\n", "path": "frappe/patches/v14_0/copy_mail_data.py"}]}