Python Forum
problems with python script and special characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problems with python script and special characters
#1
Hi,
im new to python and am trying to use the below script but when i run it i get this error:
Error:
IOError: [Errno 2] No such file or directory: '/root/user/split_=?Utf-8?Q?Temp_Glass/Mas_1213_Tempest?=\r\n =?Utf-8?Q?Tian/Kontakt_byr=C3=A5.mbox'
The python script is attached below. it analyzes an .MBOX file and split it into smaller .MBOX files based on the label name.
I've copied the script from here: https://github.com/danburzo/gmail-mbox2maildir

I think the issue is that its trying to create a folder structure but that fails. I actually dont care about the folder structure , i just need the splitted mbox files. Anyone have any ideas on how to rewrite this?

script is here in full

#!/usr/bin/env python

# Adapted from:
# http://wboptimum.com/splitting-gmail-mbox-by-label/

import sys
import getopt
import mailbox

def main(argv):
	in_mbox = "inbox.mbox"
	prefix = "split_"
	try:
		opts, args = getopt.getopt(argv, "i:p:", ["infile=", "prefix="])
	except getopt.GetoptError:
		print("python splitgmail.py -i  -p ")
		sys.exit(2)

	for opt, arg in opts:
		if opt in ("-i", "--infile"):
			in_mbox = arg
		elif opt in ("-p", "--prefix"):
			prefix = arg
	print("Processing file - " + in_mbox + " with prefix = " + prefix)
	boxes = {"inbox": mailbox.mbox(prefix+"Inbox.mbox", None, True), "sent": mailbox.mbox(prefix+"Sent.mbox", None, True),"archive":mailbox.mbox(prefix+"Archive.mbox", None, True)}

	for message in mailbox.mbox(in_mbox):
		gmail_labels = message["X-Gmail-Labels"]       # Could possibly be None.
		if not gmail_labels:
			boxes["archive"].add(message)
			continue
		gmail_labels = gmail_labels.lower()
		if "spam" in gmail_labels:
			continue
		elif "inbox" in gmail_labels:
			boxes["inbox"].add(message)
		elif "sent" in gmail_labels:
			boxes["sent"].add(message)
		else:
			saved = False
			for label in gmail_labels.split(','):
				if label != "important" and label != "unread" and label != "starred" and label != "newsletters":
					box_name = prefix+label.title()+".mbox"
					if box_name not in boxes:
						boxes[box_name] = mailbox.mbox(box_name, None, True)
					boxes[box_name].add(message)
					saved = True
					break
			if not saved:
				boxes["archive"].add(message)

if __name__ == "__main__":
    main(sys.argv[1:])
Reply
#2
Hi last08, welcome to the forums! Could you please post the entire error message? It shows more valueable information.

I assume as you have not written this script yourself, but found it somewhere online, now you don't want to learn anything about it, but just have somebody repair it for you? Correct me, if I'm wrong.

The way to go about it would be, contact the author. If you are familiar with Github, you can file an issue there, and state the error message.

If you would indeed like to understand the script and repair it yourself, we are ready to help you up to speed. Please do ask questions where you lack understanding.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 617 Mar-26-2024, 09:28 AM
Last Post: Nik1811
Question Special Characters read-write Prisonfeed 1 582 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,010 Jun-29-2023, 11:57 AM
Last Post: gologica
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,574 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  Rename Multiple files in directory to remove special characters nyawadasi 9 6,237 Feb-16-2021, 09:49 PM
Last Post: BashBedlam
  Extract continuous numeric characters from a string in Python Robotguy 2 2,584 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 3,730 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,794 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,254 May-28-2020, 05:27 PM
Last Post: micseydel
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,429 May-15-2020, 01:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020