CS160B Assignment 3: VCard++

Making VCard++

VCards are a text file format recognized for importing and exporting address book items. VCards are typically used on Macs, but are also recognized by GMail. In this assignment, you will write a program named vcard which will ask the user a series of questions in order to construct the vcard. The information asked of your user will include the name, e-mail address, optional telephone number, street address and organization.

Procedure

vcard will allow the user to enter a single vcard and either create a new file with it, or append an existing vcard file with the new entry. Your vcard program should create a current vcard in a temporary file. Then, append it to the final file when it is complete and all data has been entered correctly. The following is one suggested method of implemtation.

Your function must be free of side-effects and have a clean interface. Notice that the functions do not need arguments: each function will write it's data to standard output, which will be pre-opened by the main program.

Here is an example Vcard:


BEGIN:VCARD 
VERSION:3.0 
FN:Mr. Greg Boyd
N:Boyd;Greg;;Mr.; 
ORG:City College of San Francisco;Computer Science 
TEL;TYPE=work,voice:415-239-3139 
TEL;TYPE=cell:(415)444-4444 
EMAIL;TYPE=INTERNET:gboyd@ccsf.edu
BDAY:1980-01-14 
NOTE:Greg was in my Android class Fall 2016 
END:VCARD 

Breaking this down into sections:

The following fields are required for a VCard:

Header section. Required. Text exactly as indicated

BEGIN:VCARD 
VERSION:3.0
      

Footer section. Required. Text exactly as indicated

END:VCARD

Name section. Required. FN is a formatted name. N is a name deconstructed into pieces: Last;First;Middle(s);Prefix;Suffix. The example is Dr. Ann Marie Sue Gonzales.

FN:Dr. Ann Marie Sue Gonzales
N:Gonzales;Ann;Marie Sue;Dr.;

The following fields are optional for a VCard:

Org section. Format is ORG:Company;Department;Sub-department

ORG:ABC Co.;Marketing;
      

Tel section. Adds a telephone type. We will limit this to cell phones for this assignment We will also limit phone numbers to US numbers. (see notes for phone number verification)

TEL;TYPE=cell:(415)444-4444
      

email. simple (see notes for verification)

EMAIL;TYPE=INTERNET:gboyd@ccsf.edu
      

Birthday (Bday). YYYY-MM-DD (see notes)

BDAY:1980-01-14
      

Note - as indicated. Disallow , \ and ;

NOTE:Greg was in my class Fall 2016
      

Notes

  1. There are regular expressions you can use for verification of the email address and a US phone number in the files email_regexp and phone_regexp. Note: [[ ]] does not like either of these regexps. You will have to use grep. Feel free to cut and paste these regexps into your program. Do not rely on access to these files at runtime.

  2. You should only make the user enter one of the formats for the name. Your program should create both entries from it. (You can request the names in pieces for the N section, then construct the FN section or vice-versa.) For simplicity, do not allow Suffixes, and only allow the following Prefixes: Mr. Mrs. Ms. Dr.

  3. Comma(,),backslash(\), and semi-colon(;) are special characters in the vcard file. You can assume the user does not input them except for the ORG and NOTE field. For this assignment, if the user inputs them in these fields, give an error and abort the vcard.

  4. For the birthday, you can make them enter the pieces individually as indicated, then construct it. Note: day and month must be two-digits (i.e. 02 for 2). Make it easy for the user. For extra credit, allow the user to enter month names and convert them, or, better, allow them to enter a reasonably formatted date then check it with your own regular expression. At the very least, you must ensure that the month and year make sense. (can they have a year in the future?). Here is sample code for the bday function provided here

  5. Note that in this assignment, any error is fatal. We don't have loops yet, so the user cannot re-enter their data. If they make a mistake, tell them what happened, then return a failure status and the vcard should not be added to the file.

Testing

One way to test your vcard result is to load the file into Gmail, Go to contacts -> more-> import -> vcard format. It will take you to the old contacts page to enter it. If you give it a vcard like that above it should fill in the fields appropriately.

There is a starting file you can use if you like in the asmt03 directory on hills. It has some notes about what to do, a good number of functions to get you started (including a function fix that you can use with command-substitution to escape ; and ; characters) and code to create the temp file.