On Sat, Jul 04, 2009 at 08:07:39AM +0200, Nicolas wrote:
> Hi,
> 
> To avoid a little bug.
> 
> Indeed, in the code you have :
> if (...) {
> }
> if (...) {
> }
> ...
> 
> But, If you define a home fax number, you have :
> type == fax
> AND
> type == home


I don't think the if/else is the correct fix here either.  The if/if
was intentional at the time (right from the original time I coded it).

It looks like the meaning of TYPE is really a bitfield, using words as
the bits.  The example in RFC 2426, section 3.3.1, shows:

        TEL;TYPE=work,voice,pref,msg:+1-213-555-1234

The problem is how we map that to Blackberry fields.

The RFC gives the following TYPEs:

        "home" to indicate a telephone number associated with a residence
        "msg" to indicate the telephone number has voice messaging support
        "work" to indicate a telephone number associated with a place of work
        "pref" to indicate a preferred-use telephone number
        "voice" to indicate a voice telephone number
        "fax" to indicate a facsimile telephone number
        "cell" to indicate a cellular telephone number
        "video" to indicate a video conferencing telephone number
        "pager" to indicate a paging device telephone number
        "bbs" to indicate a bulletin board system telephone number
        "modem" to indicate a MODEM connected telephone number
        "car" to indicate a car-phone telephone number
        "isdn" to indicate an ISDN service telephone number
        "pcs" to indicate a personal communication services telephone number
        The default type is "voice".

It appears that it is legal to combine all or none of the above types,
regardless if they make sense or not.

(I don't know why the RFC thought it was necessary to differentiate between
cell and pcs phones...
http://en.wikipedia.org/wiki/Personal_Communications_Service)

The Blackberry has the following phone fields:

        (Phone)         (deprecated field in Barry)
        Fax
        WorkPhone
        HomePhone
        MobilePhone
        Pager
        Radio
        WorkPhone2
        HomePhone2
        OtherPhone


So... from the Blackberry to VCARD... (optional in parentheses)
Convert each of these fields in the following order, using the given types:

        Phone:          voice,pref      (if field is non-empty)
        Fax:            fax
        WorkPhone*:     work,voice,(msg)
        HomePhone*:     home,voice,(msg)
        MobilePhone:    msg,pref,cell
        Pager:          msg,pager
        Radio:          ignored by Barry
        OtherPhone:     voice

Doing this is fairly straightforward... basically tack on the same
TYPE codes each time you generate the VCARD.

And from VCARD to Blackberry:

        home/work       limit destination to Home* or Work* fields

        cell/pcs/car    MobilePhone field only
        pager           Pager field only
        fax             Fax field only

        pref            Overwrites existing data, or moves field1 into field2

        voice           TYPE ignored by Barry (assumed to always exist,
                        unless on of the other "only" fields exist)
        msg             TYPE ignored by Barry
        bbs/video/modem entire TEL ignored by Barry
        isdn            entire TEL ignored by Barry

Logic:

        Check for any TEL-ignore types, and throw away if present.
        Convert type codes into a bit field.
        Check for conflicts:
                pager can coexist with cell/pcs/car
                fax conflicts with cell/pcs/car
                fax conflicts with pager
        If conflict, log and ignore entire TEL.
        Else, assign "only" field to its destination.
        If anything remaining, distribute according to this logic,
                inclusively:
                        home: HomePhone or HomePhone2
                        work: WorkPhone or WorkPhone2
        If anything is marked pref, then insert into head of list, or
                overwrite existing field.

Examples:

        voice,home,work
                Will put the given TEL in the next available HomePhone *and*
                WorkPhone fields.

        home
                Put in next available HomePhone field.

        home,fax
                Put in Fax field.

        home,fax,pref
                Put in Fax field even if it already contains something.

        fax,pager
                Log an error and ignore entire TEL.

        msg,fax
                Ignore msg type and put in Fax field.

        cell,msg,voice,pref
                Ignore msg type, put in MobilePhone, and replace existing
                MobilePhone data since this is marked pref.

        home,voice,msg,pref
                Ignore msg type, copy HomePhone to HomePhone2, and put
                this TEL into HomePhone, since it is marked pref.

        bbs
                Ignored completely.


What do you think?
- Chris


Footnotes: related git commits to reference:
        f5a76b6de9ab2720a7e87b5559a4c4396a7da4dc
        c82a410246557739b1892102f61ab4362c2c385d


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Barry-devel mailing list
Barry-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/barry-devel

Reply via email to