XaviTorello / mail2googlegroup

Import email to Google Groups. Migration tool (imap and mbox)
GNU Affero General Public License v3.0
31 stars 7 forks source link

imap2gg uses port 993 instead of 143 #5

Closed rzmunch closed 3 years ago

rzmunch commented 3 years ago

When I try to use it with my mailserver, I get this error:

Error while interacting with the IMAP SERVER: '[WinError 10061] No connection could be made because the target machine actively refused it'

Sniffing my packets, it uses IMAPS in the port 993, but I only have the port 143 (not encrypted).

I did try to use ip:port but it doesn't work ( '[Errno 11001] getaddrinfo failed' )

Thanks for your help.

rzmunch commented 3 years ago

I found MailBoxUnencrypetd in imap_tools imported modified the script and got a different error:

Error while interacting with the IMAP SERVER: ''MailBoxUnencrypted' object has no attribute '_criteria_encoder''

rzmunch commented 3 years ago

I found MailBoxUnencrypetd in imap_tools imported modified the script and got a different error:

Error while interacting with the IMAP SERVER: ''MailBoxUnencrypted' object has no attribute '_criteria_encoder''

I found a workaround: put count = 1 and it worked.

So:

from imap_tools import MailBox with MailBoxUnencrypted(self.server).login( in def process --> count = 1 #self.count_elements(remote_mailbox)

Now to find a way to make it create labels for each folder. Thanks for the script.

XaviTorello commented 3 years ago

Great, ty for posting this workaround :+1:

Braintelligence commented 3 years ago

@rzmunch Hey, did you find a way to create labels for each folder? :)

EDIT: Actually I have the exact same issue @XaviTorello - do you have an idea how I could tell it to use a different port?

EDIT2: Actually no, I have the issue about Error while interacting with the IMAP SERVER: ''MailBoxUnencrypted' object has no attribute '_criteria_encoder'' but the port is correct.

Braintelligence commented 3 years ago

I altered count = 1 as well, so it would actually start again.

Then I changed the ImapImporter process like this:

def process(self):
        """
        Try to connect to the IMAP server, and try process all matched emails
        """
        try:
            with MailBox(self.server).login(
                self.email, self.password
            ) as remote_mailbox:
                for folder in remote_mailbox.folder.list():
                    print(folder["name"])
                    remote_mailbox.folder.set(folder["name"])

                    count = 1 #self.count_elements(remote_mailbox)
                    if (count == 0):
                        print(
                            "There are'nt emails to be processed",
                            f"with query '{self.query}'"
                        )
                        return

                    for an_email in tqdm(
                        remote_mailbox.fetch(self.query),
                        total=count,
                        desc='Processing emails'
                    ):

                        try:
                            prep_str = an_email.obj.as_string()
                            esubindex = prep_str.find("Subject:")
                            esub = prep_str[esubindex-1:esubindex+20]
                            new_str = prep_str[:esubindex+8] + " [" + folder["name"] + "] " + prep_str[esubindex+8:]
                            an_email_str = new_str.encode('utf-8')
                            self.push_to_group(an_email_str)
                        except Exception as e:
                            self.handle_error(e, an_email.uid, an_email_str)

                self.show_errors()

        except Exception as e:
            print(f"Error while interacting with the IMAP SERVER: '{e}'")

This way all IMAP folders are iterated on and the IMAP folder name is prefixed to the Subject of the mail before uploading it.

Sadly there seems to be no way to set a label with the google groups migration API.

sdepablos commented 3 years ago

Another one with the same _criteria_encoder error. In my case in the Mailbox: Error while interacting with the IMAP SERVER: ''MailBox' object has no attribute '_criteria_encoder', and the count=1 in the imap library also solved the issue.