PDA

View Full Version : XBMCmail script with delete function


jonkersm
2006-11-17, 23:41
I never made any script,so please help me !

I would like to add a delete function in the mailscript from burriko :
http://xbmcscripts.com/index.php?option=com_docman&task=doc_download&gid=26&Itemid=Array

I added following line at the beginning of the script :
ACTION_PARENT_DIR = 9

And then following lines after def onAction :

if action == ACTION_PARENT_DIR:
self.deletemail()

def deletemail(self):
dialog = xbmcgui.Dialog()
mail = poplib.POP3(SERVER)
mail.user(USER)
mail.pass_(PASS)
print "The server welcome message is : " , mail.getwelcome( )
numEmails = mail.stat()[0]
print "You have", numEmails, "emails"
for i in range(1, numEmails+1):
message = mail.retr(i)[1]
subject = ""
frommail = ""
for item in message:
if item.startswith("Subject"):
m = item.find("'") +9
n = item.find("'",m)
subject = item[m:n]
for item in message:
if item.startswith("From:"):
k = item.find("<") + 1
l = item.find(">",k)
frommail = item[k:l]
if dialog.yesno("Delete message from your mailbox ?","Msg " + str(i) +", FROM :" + str(frommail) + ", SUBJECT: " + str(subject) +" ?"):
print "Deleting mail ", i , " !!"
mail.dele(i)
print "Mail", i ," deleted !!"
mail.quit()
print "Connection to server closed"
time.sleep(1)

I have two problems :

1) the subject isn't (or only a part) displayed in the dialog box (is it possible to add another line in a dialog box ?)
2) I can only delete 1 mail. After deleting this mail I can't quit the script anymore

EnderW
2006-11-18, 01:32
1:

You can check for string length. It's over a certain length you can do a e.g. stringobject.split(123) or whatever it's called. Check docs on python.org for use. Then you can add them together again, but put a /n inbetween which will make the text go over a second line. Or something like that. Of course someone should implement this into XBMC itself, but I doubt that's anyone priority.

2: That you can't delete more than one mail means that you have an error in your code (obviously). If a function crash your script you often can't exit a script in XBMC so this is "normal". What the error is I don't know...you could try commenting out parts and parts and narrow it down...tedious, but that's python coding on XBMC :P

EnderW
2006-11-18, 01:36
Emm...I of course meant \n which is the same as a linebreak. You might try inserting it inbetween "Msg " + str(i) +"\nFROM :" + str(frommail) + "\nSUBJECT: " + str(subject) +" ?" and see if you get it to fit well enough without dealing with string.split().

jonkersm
2006-11-18, 14:10
Thank you EnderW !
That last tip works fine !
About 2 : the script isn't crashing but you can't leave it anymore since the on action doesn't respond anymore. So i think that I have to put something after the mail.quit()
The original total onAction looks like:

def onAction(self, action):
if action == 10:
if self.fullscreen:
self.undoFullscreen()
elif self.showingimage:
self.removeControl(self.img)
self.showingimage = False
else:
self.close()
if action == ACTION_PARENT_DIR:
self.deletemail()


Any idea ?

EnderW
2006-11-18, 17:05
Well, it doesn't crash, but there's most likely a bug in the code which prevent the action thing to go on. That's at least been the issue when I've been having the same problem. You can do an action once, but after that the onAction function just stops working. In all cases I've dealt with myself I've had a bug somewhere in my code (most likely in the self.deletemail() ).

EnderW
2006-11-18, 17:08
Also: the reason you can't exit the script, well, it seems like you'll have to press the back button 3 times if a worst case scenario...try this code or similar:

def onAction(self, action):
if action == 10:
if self.fullscreen:
self.undoFullscreen()
if self.showingimage:
self.removeControl(self.img)
self.showingimage = False
self.close()

jonkersm
2006-11-19, 15:47
I think, I found the solution !
I just added "break" after :
print "Connection to server closed"
Everything just works fine now.
I can delete as much mails I want now !

realjobe
2006-12-20, 08:35
I think, I found the solution !
I just added "break" after :
print "Connection to server closed"
Everything just works fine now.
I can delete as much mails I want now !

This sounds marvellous compiling of code!

Still the жде chars problem remains (http://xbmc.org/forum/showthread.php?p=119222#post119222)

Can some one bright take all these great changes to burriko's code and produce one skript to put on the xbmcscripts.com?

So that there are delete, charfix and otehr fixed rolled into one skript?

stanley87
2006-12-21, 03:17
I will also be adding this into my SSS mod in the near future.