#!/usr/bin/env python ## CURSES BASIC-MAIL GUI # This is the Basic-Mail program, a basic email client written in python # with a curses interface. # # To Run: Go to the Basic-Mail directory and type "python Basic-Mail.py", # without the quotes. # If it doesn't open, make sure that the size of the console window # is at least 80 x 30 pixels. ## ## Filename: files.py ## # This file contains functions that work with the save files. ## ## IMPORTS ## import curses, curses.ascii, curses.panel # Curses imports import traceback, os, sys, select, string # Random imports from variables import * # Imports all variables from draw import * # Imports the window drawing functions ## Function: Reads mail from the save file into an array ## Returns that array ## Usage: mail = readmail() def readmail(): # Read mail into array from saved text file file = open(directory + "mail.txt", "rw+") # Opens up mail text file data = file.read(-1) # Reads it into a single string mail = [] # Creates an inbox array file for inbox data y = 0 line = '' # Reads data in line by line until it is empty while data: # Reads in data by character into line line += data[0] data = data[1:] # Decide what to do with each line if data[0] == '\n': # Opens a new message if line == "250 Ok": mail.append([]) # Creates a new list in mail if len(mail) > 1: y += 1 line_num = 0 else: line_num += 1 # From: if line_num == 1: mail[y].append(line[6:]) # To: elif line_num == 2: mail[y].append(line[4:]) # Subject: elif line_num == 3: mail[y].append(line[9:]) # First line of message elif line_num == 4: mail[y].append(line) # Rest of message added on to the same string elif line_num > 4: # Not really working: length checkers """ if len(line) > 75: mail[y][3] += '\n mail[y][3] += line[:74] mail[y][3] += '\n mail[y][3] += line[74:] if len(line) > 150: mail[y][3] += '\n mail[y][3] += line[74:149] mail[y][3] += '\n mail[y][3] += line[149:] else: """ mail[y][3] += '\n' mail[y][3] += line data = data[1:] line = '' file.close() return mail