Re-importing e-mails that have already been imported

I’ve successfully installed Discourse using Digital Ocean’s cloud service with a view to migrating some listserv mailing lists if it looks like I can get Discourse to do everything we need. Whilst testing I’ve been using Thunderbird on Windows 10 to save new e-mails that come from the mailing list every few days to a folder on Windows, which I then copy to the /var/discourse/shared/standalone/import/data/ExampleCategory1 (or ExampleCategory2) folder using FileZilla. I then start the import docker and run the import_mbox.sh. So far everything has worked fine and I can manually make Discourse replicate what’s come in via the mailings lists I’m on.

However, imagine I have ExampleCategory1 and ExampleCategory2 as categories and I put the e-mails destined for the first folder, ExampleCategory1, in the second, ExampleCategory2, by mistake, then run the import before I notice. (Drag and drop went wrong on FileZilla!)

I now have the e-mails from one mailing list in the category of another, by mistake.

To fix this, I deleted all the topics/posts in ExampleCategory2 using the web interface, and also using the rake destroy:topics[“ExampleCategory2”] afterwards for good measure, with the plan to just run the import_mbox.sh again (I have copies of all the e-mails that should be in each category). However, Discourse seems to remember which e-mails it has imported, even through the posts have been deleted, and so won’t import them again!

How might I do this?

The mail received log in the admin settings section shows the incoming e-mails still that created the posts which are now deleted, but there is no hyperlink to take you to the post (as it is now deleted). I presume I have to clear out all evidence of the original incoming e-mail but I have no idea how to do this.

2 Likes

Unless you have hundreds of thousands of posts, what I recommend is to wipe the database and start over. If you want to do it a more painful way that is llkely to cause you problems, you can figure out how to delete the PostCustomFields that contain the import IDs. If you want to delete all of them, you can PostCustomField.all.destroy_all, but if you’re going to do that, then might as well do it the easy way.

2 Likes

When you say ‘wipe the database’ do you mean all topics and posts from Discourse and also all records of incoming e-mails that went through the importer (but leave the structure of the discourse and users etc intact)? Or do you mean the database of imported e-mails, which would leave existing posts in place but allow me to re-run the importer with old e-mails?

1 Like

Oh. If you’ve been running your import on a live instance that’s had users adding posts and such then you’re in a world of hurt.

If you deleted all of the imported posts then you can do something like

  PostCustomField.where(name: "import_id").destroy_all
1 Like

Many thanks @pfaffman ! That seems to have worked though I’m not entirely sure what went on behind the scenes.

I used ./launcher enter app, then typed rails c, then PostCustomField.where(name: "import_id").destroy_all and lots of writing appeared (with some parts coloured red and green), then when I exited rails and reran import_mbox.sh the original e-mails that had previously been imported then deleted by me (by removing the topics) all appeared again in discourse. If I copy e-mails to the other category folder they get reimported too, as duplicates as I suspected.

It’s only a test forum with a few additional replies as tests for people to look at before we decide whether to move or not to discourse so wiping and restarting would have been no great loss.

You also mentioned wiping the database and reimporting everything. What’s the easiest way to do the wipe?

Glad that worked! And glad that starting over won’t be an issue. I really think it’s better to start clean if you can.

The easiest way to wipe is to

   rm -r /var/discourse/shared/standalone/post*

And then rebuild. Another thing you do is to make a backup immediately after you rebuild and then you can restore that one.

1 Like