示例#1
0
def change_job_advanced(user,jobid,cslist,dialstring,filetype,jtime,addressee="",subject="",jtries="0"):
    """Change a job settings (only used for send queue)
        all params have to be comaptible to the CapiSuite job file format
        currently not used (replaced by ChangeJob() )
    """
    
    if (checkconfig() == -1) or (checkfaxuser(user,1) == 0):
        raise CSConfigError
    if not listtypes.has_key(cslist) or CheckJobID(jobid)==-1:
        raise CSInternalError("Invalid list/queue type or jobid provided")
    dialstring = ConvertDialString(dialstring)
    if not dialstring:
        raise CSUserInputError("Invalid dailstring")
    # the next two line of if-statements, limit this funtion to only
    # modify the fax send queue
    if not filetype or filetype!="sff" or not filetype!="cff":
        raise CSInternalError("Invalid job filetype (sff/cff)")
    if cslist!="faxsend":
        raise CSInternalError("Cannot modify any other queue than fax send")
    
    if not addressee:
        addressee=""
    if not subject:
        subject=""
    # CheckJobID works here also 
    if CheckJobID(jtries)==-1:
        jtries="0"

    qpath=BuildListPath(cslist,user)
    if (not os.access(qpath,os.W_OK)):
        raise CSInternalError("Can't write to queue dir: "+cslist)
    job = BuildJobFile(user,jobid,cslist)
    
    # check if job file still exists -> if not, the job might already be send or deleted
    if not os.path.exists(qpath+job):
        raise CSJobChangeError("Job doesn't exists anymore - fax already send or deleted")
    
    try:
        lockfile=open(qpath+job[:-3]+"lock","w")
        # lock so that it isn't deleted while sending
        fcntl.lockf(lockfile,fcntl.LOCK_EX | fcntl.LOCK_NB)
        cs_helpers.writeDescription(qpath+job[:-3]+filetype,"dialstring=\""+dialstring+"\"\n"
            +"starttime=\""+jtime+"\"\ntries=\""+jtries+"\"\n"
            +"user=\""+user+"\"\naddressee=\""+addressee+"\"\nsubject=\""
            +subject+"\"\n")
        fcntl.lockf(lockfile,fcntl.LOCK_UN)
        os.unlink(qpath+job[:-3]+"lock")
    except IOError,err:
        if (err.errno in (errno.EACCES,errno.EAGAIN)):
            raise CSJobChangeError("Job is currently in transmission or in similar use. Can't change it.")
        else:
            raise CSJobChangeError("Unkown access error while changing a job:"+err)
示例#2
0
def sendfax(user,dialstring,sourcefile,cstarttime="",addressee="",subject="",useprefix=None):
    if (checkconfig == -1) or (checkfaxuser(user,1) == 0) or (not sourcefile):
        raise CSConfigError
    if not dialstring:
        raise CSUserInputError("empty dialstring")
    
    if ((cs_helpers.getOption(CAPI_config,user,"outgoing_MSN","")=="") and \
        (CAPI_config.get(user,"fax_numbers","")=="")):
        raise CSGeneralError("Sorry, your are not allowed to send a fax")
    
    filetype = os.path.splitext(sourcefile)[1].lower()[1:] # splittext returns a list of 2, so no "None" check needed
    if not filetype:
        raise CSUserInputError("Invalid input (fax) file")
    
    # Convert to empty string, if set to "None"
    if addressee==None: addressee=""
    if subject==None: subject=""
    
    # filter out common separators from dialstring, check it
    dialstring=dialstring.translate(string.maketrans("",""),"-/ ()")
    if re.compile("[^0-9\+]+").search(dialstring):
        raise CSUserInputError("Invalid dialstring")

    prefix=cs_helpers.getOption(CAPI_config,user,"dial_prefix","")
    if (useprefix):
            dialstring=prefix+dialstring
    
    if (not os.access(sourcefile,os.R_OK)):
        raise CSInternalError("Cannot read fax source file:"+cgi.escape(sourcefile,1))

    sendq = os.path.join(UsersFax_Path,user,"sendq")+"/"
    newname=cs_helpers.uniqueName(sendq,"fax",filetype)
    
    # --TODO--Error check!!!!
    shutil.copy(sourcefile,newname)
    
    if not cstarttime:
        cstarttime = time.ctime()
    
    cs_helpers.writeDescription(newname,"dialstring=\""+dialstring+"\"\n"
      +"starttime=\""+cstarttime+"\"\ntries=\"0\"\n"
      +"user=\""+user+"\"\naddressee=\""+addressee+"\"\nsubject=\""
      +subject+"\"\n")
    
    os.chmod(newname,0600)
    os.chmod(newname[:-3]+"txt",0600)
    if (os.getuid()==0):
        user_entry=pwd.getpwnam(user)
        os.chown(newname,user_entry[2],user_entry[3])
        os.chown(newname[:-3]+"txt",user_entry[2],user_entry[3])
示例#3
0
def idle(capi):
	config=cs_helpers.readConfig()
	spool=cs_helpers.getOption(config,"","spool_dir")
	if (spool==None):
		capisuite.error("global option spool_dir not found.")
		return
	
	done=os.path.join(spool,"done")
	failed=os.path.join(spool,"failed")

	if (not os.access(done,os.W_OK) or not os.access(failed,os.W_OK)):
		capisuite.error("Can't read/write to the necessary spool dirs")
		return

	userlist=config.sections()
	userlist.remove('GLOBAL')

	for user in userlist: # search in all user-specified sendq's
		userdata=pwd.getpwnam(user)
		outgoing_nr=cs_helpers.getOption(config,user,"outgoing_MSN","")
                if (outgoing_nr==""):
			incoming_nrs=cs_helpers.getOption(config,user,"fax_numbers","")
			if (incoming_nrs==""):
				continue
			else:
				outgoing_nr=(incoming_nrs.split(','))[0] 

		udir=cs_helpers.getOption(config,"","fax_user_dir")
		if (udir==None):
			capisuite.error("global option fax_user_dir not found.")
			return
		udir=os.path.join(udir,user)
		sendq=os.path.join(udir,"sendq")
		if (not os.access(udir,os.F_OK)):
			os.mkdir(udir,0700)
			os.chown(udir,userdata[2],userdata[3])
		if (not os.access(sendq,os.F_OK)):
			os.mkdir(sendq,0700)
			os.chown(sendq,userdata[2],userdata[3])

		files=os.listdir(sendq)
		files=filter (lambda s: re.match("fax-.*\.txt",s),files)

		for job in files:
			job_fax="%ssff" % job[:-3]
			real_user_c=os.stat(os.path.join(sendq,job)).st_uid
			real_user_j=os.stat(os.path.join(sendq,job_fax)).st_uid
			if (real_user_j!=pwd.getpwnam(user)[2] or real_user_c!=pwd.getpwnam(user)[2]):
				capisuite.error("job %s seems to be manipulated (wrong uid)! Ignoring..." % os.path.join(sendq,job_fax))
				continue

			lockfile=open(os.path.join(sendq,"%slock" % job[:-3]),"w")
			# read directory contents
			fcntl.lockf(lockfile,fcntl.LOCK_EX) # lock so that it isn't deleted while sending

			if (not os.access(os.path.join(sendq,job),os.W_OK)): # perhaps it was cancelled?
				fcntl.lockf(lockfile,fcntl.LOCK_UN)
				lockfile.close()
				os.unlink(os.path.join(sendq,"%slock" % job[:-3]))
				continue

			control=cs_helpers.readConfig(os.path.join(sendq,job))
			# set DST value to -1 (unknown), as strptime sets it wrong for some reason
			starttime=(time.strptime(control.get("GLOBAL","starttime")))[0:8]+(-1,)
			starttime=time.mktime(starttime)
			if (starttime>time.time()):
				fcntl.lockf(lockfile,fcntl.LOCK_UN)
				lockfile.close()
				os.unlink(os.path.join(sendq,"%slock" % job[:-3]))
				continue

			tries=control.getint("GLOBAL","tries")
			dialstring=control.get("GLOBAL","dialstring")
			addressee=cs_helpers.getOption(control,"GLOBAL","addressee","")
			subject=cs_helpers.getOption(control,"GLOBAL","subject","")
			mailaddress=cs_helpers.getOption(config,user,"fax_email","")
			if (mailaddress==""):
				mailaddress=user
			fromaddress=cs_helpers.getOption(config,user,"fax_email_from","")
			if (fromaddress==""):
				fromaddress=user

			capisuite.log("job %s from %s to %s initiated" % (job_fax,user,dialstring),1)
			result,resultB3 = sendfax(capi,os.path.join(sendq,job_fax),outgoing_nr,dialstring,user,config)
			tries+=1
			capisuite.log("job %s: result was %x,%x" % (job_fax,result,resultB3),1)

			if (result in (0,0x3400,0x3480,0x3490,0x349f) and resultB3==0):
				movejob(job_fax,sendq,done,user)
				capisuite.log("job %s: finished successfully" % job_fax,1)
				mailtext="Your fax job to %s (%s) was sent successfully.\n\n" \
				  "Subject: %s\nFilename: %s\nNeeded tries: %i\n" \
				  "Last result: 0x%x/0x%x\n\nIt was moved to " \
				  "file://%s on host \"%s\"" % (addressee,dialstring, \
				  subject,job_fax,tries,result,resultB3, \
				  os.path.join(done,"%s-%s" % (user,job_fax)), \
				  os.uname()[1])
				cs_helpers.sendSimpleMail(fromaddress,mailaddress,
				  "Fax to %s (%s) sent successfully." % (addressee,dialstring),
				  mailtext)
			else:
				max_tries=int(cs_helpers.getOption(config,"","send_tries","10"))
				delays=cs_helpers.getOption(config,"","send_delays","60,60,60,300,300,3600,3600,18000,36000").split(",")
				delays=map(int,delays)
				if ((tries-1)<len(delays)):
					next_delay=delays[tries-1]
				else:
					next_delay=delays[-1]
				starttime=time.time()+next_delay
				capisuite.log("job %s: delayed for %i seconds" % (job_fax,next_delay),2)
				cs_helpers.writeDescription(os.path.join(sendq,job_fax), \
				  "dialstring=\"%s\"\nstarttime=\"%s\"\ntries=\"%i\"\n" \
				  "user=\"%s\"\naddressee=\"%s\"\nsubject=\"%s\"\n" \
				  % (dialstring,time.ctime(starttime),tries,user, \
				  addressee,subject))
				if (tries>=max_tries):
					movejob(job_fax,sendq,failed,user)
					capisuite.log("job %s: failed finally" % job_fax,1)
					mailtext="I'm sorry, but your fax job to %s (%s) " \
					  "failed finally.\n\nSubject: %s\n" \
					  "Filename: %s\nTries: %i\n" \
					  "Last result: 0x%x/0x%x\n\n" \
					  "It was moved to file://%s-%s on host %s.\n\n" \
					  % (addressee,dialstring,subject,job_fax,tries,result, \
					  resultB3,os.path.join(failed,user),job_fax,os.uname()[1]) 
					cs_helpers.sendSimpleMail(fromaddress,mailaddress,
					  "Fax to %s (%s) FAILED." % (addressee,dialstring),
					  mailtext)

			fcntl.lockf(lockfile,fcntl.LOCK_UN)
			lockfile.close()
			os.unlink("%slock" % os.path.join(sendq,job[:-3]))
示例#4
0
def faxIncoming(call,call_from,call_to,curr_user,config,already_connected):
	try:
		udir=cs_helpers.getOption(config,"","fax_user_dir")
		if (udir==None):
			capisuite.error("global option fax_user_dir not found! -> rejecting call")
			capisuite.reject(call,0x34A9)
			return
		udir=os.path.join(udir,curr_user)+"/"
		if (not os.access(udir,os.F_OK)):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(udir,0700)
			os.chown(udir,userdata[2],userdata[3])
		if (not os.access(udir+"received/",os.F_OK)):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(udir+"received/",0700)
			os.chown(udir+"received/",userdata[2],userdata[3])
	except KeyError:
		capisuite.error("user "+curr_user+" is not a valid system user. Disconnecting",call)
		capisuite.reject(call,0x34A9)
		return
	filename="" # assure the variable is defined...
	try:
		stationID=cs_helpers.getOption(config,curr_user,"fax_stationID")
		if (stationID==None):
			capisuite.error("Warning: fax_stationID not found for user "+curr_user+" -> using empty string")
			stationID=""
		headline=cs_helpers.getOption(config,curr_user,"fax_headline","") # empty string is no problem here
		capisuite.log("call from "+call_from+" to "+call_to+" for "+curr_user+" connecting with fax",1,call)
		if (already_connected):
			faxInfo=capisuite.switch_to_faxG3(call,stationID,headline)
		else:
			faxInfo=capisuite.connect_faxG3(call,stationID,headline,0)
		if (faxInfo!=None and faxInfo[3]==1):
			faxFormat="cff" # color fax
		else:
			faxFormat="sff" # normal b&w fax
		filename=cs_helpers.uniqueName(udir+"received/","fax",faxFormat)
		capisuite.fax_receive(call,filename)
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection finished with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	except capisuite.CallGoneError: # catch this here to get the cause info in the mail
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection lost with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	if (os.access(filename,os.R_OK)):
		cs_helpers.writeDescription(filename,
		  "call_from=\""+call_from+"\"\ncall_to=\""+call_to+"\"\ntime=\""
		  +time.ctime()+"\"\ncause=\"0x%x/0x%x\"\n" % (cause,causeB3))
		userdata=pwd.getpwnam(curr_user)
		os.chmod(filename,0600)
		os.chown(filename,userdata[2],userdata[3])
		os.chmod(filename[:-3]+"txt",0600)
		os.chown(filename[:-3]+"txt",userdata[2],userdata[3])

		fromaddress=cs_helpers.getOption(config,curr_user,"fax_email_from","")
		if (fromaddress==""):
			fromaddress=curr_user
		mailaddress=cs_helpers.getOption(config,curr_user,"fax_email","")
		if (mailaddress==""):
			mailaddress=curr_user
                action=cs_helpers.getOption(config,curr_user,"fax_action","").lower()
		if (action not in ("mailandsave","saveonly")):
			capisuite.error("Warning: No valid fax_action definition found for user "+curr_user+" -> assuming SaveOnly")
			action="saveonly"
		if (action=="mailandsave"):
			cs_helpers.sendMIMEMail(fromaddress, mailaddress, "Fax received from "+call_from+" to "+call_to, faxFormat,
			  "You got a fax from "+call_from+" to "+call_to+"\nDate: "+time.ctime()+"\n\n"
			  +"See attached file.\nThe original file was saved to file://"+filename+"\n\n", filename)
示例#5
0
def voiceIncoming(call,call_from,call_to,curr_user,config):
	try:
		udir=cs_helpers.getOption(config,"","voice_user_dir")
		if (udir==None):
			capisuite.error("global option voice_user_dir not found! -> rejecting call")
			capisuite.reject(call,0x34A9)
			return
		udir=os.path.join(udir,curr_user)+"/"
		if (not os.access(udir,os.F_OK)):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(udir,0700)
			os.chown(udir,userdata[2],userdata[3])
		if (not os.access(udir+"received/",os.F_OK)):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(udir+"received/",0700)
			os.chown(udir+"received/",userdata[2],userdata[3])
	except KeyError:
		capisuite.error("user "+curr_user+" is not a valid system user. Disconnecting",call)
		capisuite.reject(call,0x34A9)
		return
	filename=cs_helpers.uniqueName(udir+"received/","voice","la")
	action=cs_helpers.getOption(config,curr_user,"voice_action","").lower()
	if (action not in ("mailandsave","saveonly","none")):
		capisuite.error("Warning: No valid voice_action definition found for user "+curr_user+" -> assuming SaveOnly")
		action="saveonly"
	try:
		capisuite.enable_DTMF(call)
		userannouncement=udir+cs_helpers.getOption(config,curr_user,"announcement","announcement.la")
		pin=cs_helpers.getOption(config,curr_user,"pin","")
		if (os.access(userannouncement,os.R_OK)):
			capisuite.audio_send(call,userannouncement,1)
		else:
			if (call_to!="-"):
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"anrufbeantworter-von.la"),1)
				cs_helpers.sayNumber(call,call_to,curr_user,config)
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"bitte-nachricht.la"),1)

		if (action!="none"):
			capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"),1)
			length=cs_helpers.getOption(config,curr_user,"record_length","60")
			silence_timeout=cs_helpers.getOption(config,curr_user,"record_silence_timeout","5")
			capisuite.audio_receive(call,filename,int(length), int(silence_timeout),1)

		dtmf_list=capisuite.read_DTMF(call,0)
		if (dtmf_list=="X"):
			if (os.access(filename,os.R_OK)):
				os.unlink(filename)
			faxIncoming(call,call_from,call_to,curr_user,config,1)
		elif (dtmf_list!="" and pin!=""):
			dtmf_list+=capisuite.read_DTMF(call,3) # wait 5 seconds for input
			count=1
			while (count<3 and pin!=dtmf_list):  # try again if input was wrong
				capisuite.log("wrong PIN entered...",1,call)
				capisuite.audio_send(call,cs_helpers.getAudio(config,curr_user,"beep.la"))
				dtmf_list=capisuite.read_DTMF(call,3)
				count+=1
			if (pin==dtmf_list):
				if (os.access(filename,os.R_OK)):
					os.unlink(filename)
				capisuite.log("Starting remote inquiry...",1,call)
				remoteInquiry(call,udir,curr_user,config)

		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection finished with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	except capisuite.CallGoneError: # catch this here to get the cause info in the mail
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection lost with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	if (os.access(filename,os.R_OK)):
		cs_helpers.writeDescription(filename,
		  "call_from=\""+call_from+"\"\ncall_to=\""+call_to+"\"\ntime=\""
		  +time.ctime()+"\"\ncause=\"0x%x/0x%x\"\n" % (cause,causeB3))
		userdata=pwd.getpwnam(curr_user)
		os.chmod(filename,0600)
		os.chown(filename,userdata[2],userdata[3])
		os.chmod(filename[:-2]+"txt",0600)
		os.chown(filename[:-2]+"txt",userdata[2],userdata[3])

		fromaddress=cs_helpers.getOption(config,curr_user,"voice_email_from","")
		if (fromaddress==""):
			fromaddress=curr_user
		mailaddress=cs_helpers.getOption(config,curr_user,"voice_email","")
		if (mailaddress==""):
			mailaddress=curr_user
		if (action=="mailandsave"):
			cs_helpers.sendMIMEMail(fromaddress, mailaddress, "Voice call received from "+call_from+" to "+call_to, "la",
			  "You got a voice call from "+call_from+" to "+call_to+"\nDate: "+time.ctime()+"\n\n"
			  +"See attached file.\nThe original file was saved to file://"+filename+"\n\n", filename)
示例#6
0
def faxIncoming(call,call_from,call_to,curr_user,config,already_connected):
	try:
		udir=cs_helpers.getOption(config,"","fax_user_dir")
		if (udir==None):
			capisuite.error("global option fax_user_dir not found! -> rejecting call")
			capisuite.reject(call,0x34A9)
			return
		udir=os.path.join(udir,curr_user)
		if (not os.path.exists(udir)):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(udir,0700)
			os.chown(udir,userdata[2],userdata[3])
		if (not os.path.exists(os.path.join(udir,"received"))):
			userdata=pwd.getpwnam(curr_user)
			os.mkdir(os.path.join(udir,"received"),0700)
			os.chown(os.path.join(udir,"received"),userdata[2],userdata[3])
	except KeyError:
		capisuite.error("user %s is not a valid system user. Disconnecting" % curr_user,call)
		capisuite.reject(call,0x34A9)
		return
	filename="" # assure the variable is defined...
	faxInfo=None
	try:
		stationID=cs_helpers.getOption(config,curr_user,"fax_stationID")
		if (stationID==None):
			capisuite.error("Warning: fax_stationID not found for user %s -> using empty string" % curr_user)
			stationID=""
		headline=cs_helpers.getOption(config,curr_user,"fax_headline","") # empty string is no problem here
		capisuite.log("call from %s to %s for %s connecting with fax" % (call_from,call_to,curr_user),1,call)
		if (already_connected):
			faxInfo=capisuite.switch_to_faxG3(call,stationID,headline)
		else:
			faxInfo=capisuite.connect_faxG3(call,stationID,headline,0)
		if (faxInfo!=None and faxInfo[3]==1):
			faxFormat="cff" # color fax
		else:
			faxFormat="sff" # normal b&w fax
		filename=cs_helpers.uniqueName(os.path.join(udir,"received"),"fax",faxFormat)
		faxInfo=capisuite.fax_receive(call,filename)
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection finished with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	except capisuite.CallGoneError: # catch this here to get the cause info in the mail
		(cause,causeB3)=capisuite.disconnect(call)
		capisuite.log("connection lost with cause 0x%x,0x%x" % (cause,causeB3),1,call)

	if (os.access(filename,os.R_OK)):
		cs_helpers.writeDescription(filename,
		  "call_from=\"%s\"\ncall_to=\"%s\"\ntime=\"%s\"\n" \
		  "cause=\"0x%x/0x%x\"\n" % (call_from,call_to,time.ctime(),cause,causeB3))
		userdata=pwd.getpwnam(curr_user)
		os.chmod(filename,0600)
		os.chown(filename,userdata[2],userdata[3])
		os.chmod("%stxt" % filename[:-3],0600)
		os.chown("%stxt" % filename[:-3],userdata[2],userdata[3])

		fromaddress=cs_helpers.getOption(config,curr_user,"fax_email_from","")
		if (fromaddress==""):
			fromaddress=curr_user
		mailaddress=cs_helpers.getOption(config,curr_user,"fax_email","")
		if (mailaddress==""):
			mailaddress=curr_user
                action=cs_helpers.getOption(config,curr_user,"fax_action","").lower()
		if (action not in ("mailandsave","saveonly")):
			capisuite.error("Warning: No valid fax_action definition found for user %s -> assuming SaveOnly" % curr_user)
			action="saveonly"
		if (action=="mailandsave"):
			mailText="You got a fax from %s to %s\nDate: %s" % (call_from,call_to,time.ctime())
			if (faxInfo!=None and len(faxInfo)>=5):
				mailText="%sStation ID: %s\nTransmission Details: bit rate %i " \
				  "%s %s\nPages: %i\n\nSee attached file.\n" \
				  "The original file was saved to file://%s " \
				  "on host \"%s\"." % (mailText,faxInfo[0], \
				  faxInfo[1],(faxInfo[2] and "hiRes" or "loRes"), \
				  (faxInfo[3] and "color" or ""),faxInfo[4], \
				  fileName,os.uname()[1])
			cs_helpers.sendMIMEMail(fromaddress, mailaddress, "Fax received from %s to %s" % (call_from,call_to),
			  faxFormat, mailText, filename)
示例#7
0
        subject=cs_helpers.getOption(control,"GLOBAL","subject","")

    jtries = control.get("GLOBAL","tries")
    datafile = control.get("GLOBAL","filename")
    
    # check if job file still exists -> if not, the job might already be send or deleted
    # this check might be obselete since cs_helpers.readConfig(..) is used in this function...
    if not os.path.exists(qpath+jobfile):
        raise CSJobChangeError("Job doesn't exists anymore - fax already send or deleted")
    
    try:
        lockfile=open(qpath+jobfile[:-3]+"lock","w")
        # lock so that it isn't deleted while sending
        fcntl.lockf(lockfile,fcntl.LOCK_EX | fcntl.LOCK_NB)
        cs_helpers.writeDescription(datafile,"dialstring=\""+dialstring+"\"\n"
            +"starttime=\""+starttime+"\"\ntries=\""+jtries+"\"\n"
            +"user=\""+user+"\"\naddressee=\""+addressee+"\"\nsubject=\""
            +subject+"\"\n")
        fcntl.lockf(lockfile,fcntl.LOCK_UN)
        os.unlink(qpath+jobfile[:-3]+"lock")
    except IOError,err:
        if (err.errno in (errno.EACCES,errno.EAGAIN)):
            raise CSJobChangeError("Job is currently in transmission or in similar use. Can't change it.")
        else:
            raise CSJobChangeError("Unkown access error while changing a job:"+err)
    
def CheckDialString(dialstring):
    """check a dialstring, allows typical "help chars"/separators"""    
    if not dialstring:
        return -1
    if re.compile("[^0-9+()/\- ]+").search(dialstring):
        return -1