The Signature Wizard

Wednesday 9th August, 2006
Image:The Signature Wizard
He may be a Geek, but in some ways Rocky Oliver is a wizard...at least when it comes to signatures.

We've been rolling out Rocky's Signature Wizard utility to all our UK staff with great effect, unfortunately we've hit a hurdle with Nordic characters in Europe.

We first noticed a problem with Swedish letters å, ä, ö but now realise it extends to all non-ASCII characters in english names. All the unknown characters are replaced with the question mark (?) character as the .htm file gets written and J?ffa just doesn't look right in someone's name.

Rocky was kind enough to assist via IM and suggest I replace part of the script and use UTF-8, UTF-16 or Unicode character sets but we haven't had much success yet. We need to find the right codepage for these character sets and, so far, I'm flying blind. I figured I'd end up blogging the solution anyway so decided to blog the problem as well.

Any ideas anyone?

  1. 1) Matt White Said: (09/08/2006 16:23:30 GMT) Gravatar Image
    The Signature Wizard

    Ben,

    When I've had to do work with Swedish characters in the past using the ISO-8859-1 character set in my XML has done the job for me:

    { Link }

    Hope this helps.

    Matt

  2. 2) Ben Poole Said: (09/08/2006 16:28:43 GMT) Gravatar Image
    The Signature Wizard

    Seconded for ISO-8859-1, that should work.

    But then, so should UTF-8. How does the wizard insert the relevant characters? i.e. what does the source html actually look like? Simple escaped HTML entities have always worked for me...

  3. 3) Ben Rose Said: (10/08/2006 08:22:39 GMT) Gravatar Image
    The Signature Wizard

    Matt/Ben,

    Thanks for the input but we already tried that ISO setup without success.

    Here's the code in use, it results in a .htm file on the hard drive which contains ? characters where the foreign ones were:

    Sub Click(Source As Button)

    Const HTML_FILENAME = "tfs_sig.htm"

    Const LOGO_FILENAME = "tfs.jpg"

    Const SIG_DIRECTORY = "c:\emailsignature"

    Dim s As New NotesSession, ws As New NotesUIWorkspace

    Dim thisdb As NotesDatabase, thisdoc As NotesDocument

    Dim mailprof As NotesDocument ' Mail Preferences profile

    Dim userdir As String, sigpath As String, sigpicpath As String

    Dim userinfo List As String

    Dim sigstream As NotesStream, sigcode As String

    Dim retflg As Boolean, chgpic As Integer

    Dim newpicpath As Variant, newfilename As String, userdirdef As String

    Set thisdb = s.CurrentDatabase

    Set thisdoc = ws.CurrentDocument.Document

    If Dir$(SIG_DIRECTORY,16) = "" Then Mkdir SIG_DIRECTORY

    sigpath = SIG_DIRECTORY & "\"

    sigpicpath = sigpath & LOGO_FILENAME

    sigpath = sigpath & HTML_FILENAME

    REM set up user info list

    userinfo("name") = "Your Name"

    userinfo("job title") = "Job Title"

    userinfo("company") = "Company name"

    userinfo("phone") = "+44 (0)1234 56 xxxx"

    userinfo("fax") = "+44 (0)1234 56 xxxx"

    userinfo("email") = "first.last@company.com"

    REM prompt for user info

    Msgbox "You are about to be asked a series of questions that will be used to set up your signature file." & Chr(10) &_

    "Ready? Good! Let's begin...", 64, "Signature Creation"

    Print "Prompting for user info..."

    Forall u In userinfo

    u = Inputbox("Please enter your " & Listtag(u) & ":", Ucase(Listtag(u)), u)

    End Forall

    Print "Detaching files..."

    REM don't ask if they want to change from the default graphic

    chgpic = 5

    If chgpic = 6 Then

    userdirdef = Environ("USERPROFILE")

    newpicpath = ws.OpenFileDialog(False, "New Sig Graphic", "All files|*.*|Bitmap|*.bmp|JPEG|*.jpg|GIF|*.gif", _

    userdirdef & "\My Documents\My Pictures", "*.*")

    REM since a new graphic was chosen we need to copy it to the target dir

    If Isempty(newpicpath) Then

    retflg = detachFile(thisdoc, "Body", LOGO_FILENAME, sigpicpath)

    Else

    newfilename = Strleftback(LOGO_FILENAME, ".") & "." & Strrightback(newpicpath(0), ".")

    Filecopy newpicpath(0), SIG_DIRECTORY & "\" & newfilename ' gets the right extension

    End If

    Else

    retflg = detachFile(thisdoc, "Body", LOGO_FILENAME, sigpicpath)

    End If

    REM now update the file

    REM detach it first

    retflg = detachFile(thisdoc, "Body", HTML_FILENAME, sigpath)

    Print "Loading sig file into code..."

    REM load the sig file into a var

    Set sigstream = s.CreateStream

    If Not sigstream.Open(sigpath, "ISO-8859-1") Then Error 1000, "Unable to open file stream: " & sigpath

    sigstream.Position = 0

    sigcode = sigstream.ReadText

    Call sigstream.Close

    Print "Updating sig code..."

    REM update the code with the info

    Forall i In userinfo

    sigcode = ReplaceChars(sigcode, "%%" & Listtag(i) & "%%", i)

    End Forall

    If newfilename <> "" Then sigcode = ReplaceChars(sigcode, LOGO_FILENAME, newfilename) ' in case the new graphic has a different extension

    Print "Writing sig file back to the file (" & sigpath & ")..."

    REM write the updated code back to the file

    Set sigstream = s.CreateStream

    If Not sigstream.Open(sigpath, "ASCII") Then Error 1000, "Unable to open file stream: " & sigpath

    Call sigstream.Truncate ' empties the file if there is stuff in it

    Call sigstream.WriteText(sigcode, EOL_CRLF)

    Call sigstream.Close

    Delete sigstream ' to make sure the handle is released

    Print "Sig file creation complete - enabling sig file for mail..."

    Print "Getting handle to Mail Preferences..."

    Set mailprof = thisdb.GetProfileDocument("CalendarProfile")

    Call mailprof.ReplaceItemValue("EnableSignature", "1")

    Call mailprof.ReplaceItemValue("SignatureOption", "2")

    Call mailprof.ReplaceItemValue("Signature_2", sigpath)

    Call mailprof.ComputeWithForm(True, False)

    Call mailprof.Save(True, False)

    Print "Mail sig enabled - enjoy!"

    Print "Signature Created."

    getOut:

    Exit Sub

    errHandler:

    Select Case Err

    Case 1000

    Msgbox Error$,, "Error"

    Case Else

    Msgbox Error$ & " (err: " & Err & ", erl: " & Erl & ")",, "Error"

    End Select

    Resume getOut

    End Sub

  4. 4) Matt White Said: (10/08/2006 09:46:42 GMT) Gravatar Image
    The Signature Wizard

    Ben,

    I think you're trying the character setting in the wrong place, the problem is not occurring when you read in the stream, but when it gets written back out to the html file. So if you change the line:

    If Not sigstream.Open(sigpath, "ASCII") Then Error 1000, "Unable to open file stream: " & sigpath

    to be

    If Not sigstream.Open(sigpath, "ISO-8859-1") Then Error 1000, "Unable to open file stream: " & sigpath

    Then I think you should be OK.

    (Although this is just from my quick scan of the code, Rocky will probably know the answer in a second if you drop him a line!)

    Matt

  5. 5) Matt White Said: (10/08/2006 09:47:45 GMT) Gravatar Image
    The Signature Wizard

    Oops just realised that line appears twice, you want to be changing the second instance of it, not the first!

    Matt

  6. 6) Ben Rose Said: (10/08/2006 11:53:09 GMT) Gravatar Image
    The Signature Wizard

    Matt,

    We've had it in the first and the second, either place it's not working.

Add Comment
 
Subject:
   
Name:
E-mail:
Web Site:
 
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?