Search code examples
pythonoutlookpyqtdrag-and-droppyqt5

How can I download the Outlook mail by dragging it to PyQt5 area?


I am learning the drag and drop part of pyqt5. Most files can know the path of the file when dragged to pyqt. However, the actual path cannot be found because the actual location of the Outlook mail exists in the .pst file. So, when dragging and dropping the Outlook mail to a specific layout in pyqt, I want to download the Outlook mail to a specific folder.

Is there a better way? Or can you give me advice?

Please Help me..!! (I've been up all night for 3 days because of this problem)

This picture is what I want. enter image description here

The code block in this part is empty, and I want to fill out the above.

    def dragMoveEvent(self, event):
        if event.mimeData().hasUrls() or event.mimeData().hasFormat("FileContents"):
            event.setDropAction(Qt.CopyAction)
            event.accept()
        else:
            event.ignore()

    def dropEvent(self, event):
        if event.mimeData().hasFormat("FileContents"):
            event.setDropAction(Qt.CopyAction)
            event.accept()
            print(event.mimeData().text())

Solution

  • When you try to drag and drop from Outlook, Outlook correctly identifies the format as virtual files (CFSTR_FILEDESCRIPTORW) since the files do not exist directly on disk. Instead, they are contained in a PST file, OST file, or on an Exchange server.

    Read more about the drag and drop operations in Outlook in the following articles: