Mercurial > libpst
comparison src/readpst.c @ 242:67b24d6a45d6 stable-0-6-45
patch from Hugo DesRosiers to export categories and notes into vcards.
extend that patch to export categories into vcalendar appointments also.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 11 Dec 2009 08:45:30 -0800 |
parents | aa50c23a6935 |
children | 5a82d41c883d 97c53c6868ab |
comparison
equal
deleted
inserted
replaced
241:fa4042b0a566 | 242:67b24d6a45d6 |
---|---|
56 void write_body_part(FILE* f_output, pst_string *body, char *mime, char *charset, char *boundary, pst_file* pst); | 56 void write_body_part(FILE* f_output, pst_string *body, char *mime, char *charset, char *boundary, pst_file* pst); |
57 void write_schedule_part_data(FILE* f_output, pst_item* item, const char* sender, const char* method); | 57 void write_schedule_part_data(FILE* f_output, pst_item* item, const char* sender, const char* method); |
58 void write_schedule_part(FILE* f_output, pst_item* item, const char* sender, const char* boundary); | 58 void write_schedule_part(FILE* f_output, pst_item* item, const char* sender, const char* boundary); |
59 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf, char** extra_mime_headers); | 59 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf, char** extra_mime_headers); |
60 void write_vcard(FILE* f_output, pst_item *item, pst_item_contact* contact, char comment[]); | 60 void write_vcard(FILE* f_output, pst_item *item, pst_item_contact* contact, char comment[]); |
61 int write_extra_categories(FILE* f_output, pst_item* item); | |
61 void write_journal(FILE* f_output, pst_item* item); | 62 void write_journal(FILE* f_output, pst_item* item); |
62 void write_appointment(FILE* f_output, pst_item *item, int event_open); | 63 void write_appointment(FILE* f_output, pst_item *item); |
63 void create_enter_dir(struct file_ll* f, pst_item *item); | 64 void create_enter_dir(struct file_ll* f, pst_item *item); |
64 void close_enter_dir(struct file_ll *f); | 65 void close_enter_dir(struct file_ll *f); |
65 | 66 |
66 const char* prog_name; | 67 const char* prog_name; |
67 char* output_dir = "."; | 68 char* output_dir = "."; |
1277 fprintf(f_output, "VERSION:2.0\n"); | 1278 fprintf(f_output, "VERSION:2.0\n"); |
1278 fprintf(f_output, "PRODID:LibPST v%s\n", VERSION); | 1279 fprintf(f_output, "PRODID:LibPST v%s\n", VERSION); |
1279 if (method) fprintf(f_output, "METHOD:%s\n", method); | 1280 if (method) fprintf(f_output, "METHOD:%s\n", method); |
1280 fprintf(f_output, "BEGIN:VEVENT\n"); | 1281 fprintf(f_output, "BEGIN:VEVENT\n"); |
1281 if (sender) fprintf(f_output, "ORGANIZER;CN=\"%s\":MAILTO:%s\n", item->email->outlook_sender_name.str, sender); | 1282 if (sender) fprintf(f_output, "ORGANIZER;CN=\"%s\":MAILTO:%s\n", item->email->outlook_sender_name.str, sender); |
1282 write_appointment(f_output, item, 1); | 1283 write_appointment(f_output, item); |
1283 fprintf(f_output, "END:VCALENDAR\n"); | 1284 fprintf(f_output, "END:VCALENDAR\n"); |
1284 } | 1285 } |
1285 | 1286 |
1286 | 1287 |
1287 void write_schedule_part(FILE* f_output, pst_item* item, const char* sender, const char* boundary) | 1288 void write_schedule_part(FILE* f_output, pst_item* item, const char* sender, const char* boundary) |
1671 pst_convert_utf8_null(item, &contact->job_title); | 1672 pst_convert_utf8_null(item, &contact->job_title); |
1672 pst_convert_utf8_null(item, &contact->profession); | 1673 pst_convert_utf8_null(item, &contact->profession); |
1673 pst_convert_utf8_null(item, &contact->assistant_name); | 1674 pst_convert_utf8_null(item, &contact->assistant_name); |
1674 pst_convert_utf8_null(item, &contact->assistant_phone); | 1675 pst_convert_utf8_null(item, &contact->assistant_phone); |
1675 pst_convert_utf8_null(item, &contact->company_name); | 1676 pst_convert_utf8_null(item, &contact->company_name); |
1677 pst_convert_utf8_null(item, &item->body); | |
1676 | 1678 |
1677 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile | 1679 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile |
1678 fprintf(f_output, "BEGIN:VCARD\n"); | 1680 fprintf(f_output, "BEGIN:VCARD\n"); |
1679 fprintf(f_output, "FN:%s\n", pst_rfc2426_escape(contact->fullname.str, &result, &resultlen)); | 1681 fprintf(f_output, "FN:%s\n", pst_rfc2426_escape(contact->fullname.str, &result, &resultlen)); |
1680 | 1682 |
1754 if (contact->assistant_name.str) fprintf(f_output, "FN:%s\n", pst_rfc2426_escape(contact->assistant_name.str, &result, &resultlen)); | 1756 if (contact->assistant_name.str) fprintf(f_output, "FN:%s\n", pst_rfc2426_escape(contact->assistant_name.str, &result, &resultlen)); |
1755 if (contact->assistant_phone.str) fprintf(f_output, "TEL:%s\n", pst_rfc2426_escape(contact->assistant_phone.str, &result, &resultlen)); | 1757 if (contact->assistant_phone.str) fprintf(f_output, "TEL:%s\n", pst_rfc2426_escape(contact->assistant_phone.str, &result, &resultlen)); |
1756 } | 1758 } |
1757 if (contact->company_name.str) fprintf(f_output, "ORG:%s\n", pst_rfc2426_escape(contact->company_name.str, &result, &resultlen)); | 1759 if (contact->company_name.str) fprintf(f_output, "ORG:%s\n", pst_rfc2426_escape(contact->company_name.str, &result, &resultlen)); |
1758 if (comment) fprintf(f_output, "NOTE:%s\n", pst_rfc2426_escape(comment, &result, &resultlen)); | 1760 if (comment) fprintf(f_output, "NOTE:%s\n", pst_rfc2426_escape(comment, &result, &resultlen)); |
1761 if (item->body.str) fprintf(f_output, "NOTE:%s\n", pst_rfc2426_escape(item->body.str, &result, &resultlen)); | |
1762 | |
1763 write_extra_categories(f_output, item); | |
1759 | 1764 |
1760 fprintf(f_output, "VERSION: 3.0\n"); | 1765 fprintf(f_output, "VERSION: 3.0\n"); |
1761 fprintf(f_output, "END:VCARD\n\n"); | 1766 fprintf(f_output, "END:VCARD\n\n"); |
1762 if (result) free(result); | 1767 if (result) free(result); |
1763 DEBUG_RET(); | 1768 DEBUG_RET(); |
1769 } | |
1770 | |
1771 | |
1772 /** | |
1773 * write extra vcard or vcalendar categories from the extra keywords fields | |
1774 * | |
1775 * @param f_output open file pointer | |
1776 * @param item pst item containing the keywords | |
1777 * @return true if we write a categories line | |
1778 */ | |
1779 int write_extra_categories(FILE* f_output, pst_item* item) | |
1780 { | |
1781 char* result = NULL; | |
1782 size_t resultlen = 0; | |
1783 pst_item_extra_field *ef = item->extra_fields; | |
1784 const char *fmt = "CATEGORIES:%s"; | |
1785 int category_started = 0; | |
1786 while (ef) { | |
1787 if (strcmp(ef->field_name, "Keywords") == 0) { | |
1788 fprintf(f_output, fmt, pst_rfc2426_escape(ef->value, &result, &resultlen)); | |
1789 fmt = ", %s"; | |
1790 category_started = 1; | |
1791 } | |
1792 ef = ef->next; | |
1793 } | |
1794 if (category_started) fprintf(f_output, "\n"); | |
1795 if (result) free(result); | |
1796 return category_started; | |
1764 } | 1797 } |
1765 | 1798 |
1766 | 1799 |
1767 void write_journal(FILE* f_output, pst_item* item) | 1800 void write_journal(FILE* f_output, pst_item* item) |
1768 { | 1801 { |
1790 fprintf(f_output, "END:VJOURNAL\n"); | 1823 fprintf(f_output, "END:VJOURNAL\n"); |
1791 if (result) free(result); | 1824 if (result) free(result); |
1792 } | 1825 } |
1793 | 1826 |
1794 | 1827 |
1795 void write_appointment(FILE* f_output, pst_item* item, int event_open) | 1828 void write_appointment(FILE* f_output, pst_item* item) |
1796 { | 1829 { |
1797 char* result = NULL; | 1830 char* result = NULL; |
1798 size_t resultlen = 0; | 1831 size_t resultlen = 0; |
1799 char time_buffer[30]; | 1832 char time_buffer[30]; |
1800 pst_item_appointment* appointment = item->appointment; | 1833 pst_item_appointment* appointment = item->appointment; |
1802 // make everything utf8 | 1835 // make everything utf8 |
1803 pst_convert_utf8_null(item, &item->subject); | 1836 pst_convert_utf8_null(item, &item->subject); |
1804 pst_convert_utf8_null(item, &item->body); | 1837 pst_convert_utf8_null(item, &item->body); |
1805 pst_convert_utf8_null(item, &appointment->location); | 1838 pst_convert_utf8_null(item, &appointment->location); |
1806 | 1839 |
1807 if (!event_open) fprintf(f_output, "BEGIN:VEVENT\n"); | |
1808 fprintf(f_output, "DTSTAMP:%s\n", pst_rfc2445_datetime_format_now(sizeof(time_buffer), time_buffer)); | 1840 fprintf(f_output, "DTSTAMP:%s\n", pst_rfc2445_datetime_format_now(sizeof(time_buffer), time_buffer)); |
1809 if (item->create_date) | 1841 if (item->create_date) |
1810 fprintf(f_output, "CREATED:%s\n", pst_rfc2445_datetime_format(item->create_date, sizeof(time_buffer), time_buffer)); | 1842 fprintf(f_output, "CREATED:%s\n", pst_rfc2445_datetime_format(item->create_date, sizeof(time_buffer), time_buffer)); |
1811 if (item->modify_date) | 1843 if (item->modify_date) |
1812 fprintf(f_output, "LAST-MOD:%s\n", pst_rfc2445_datetime_format(item->modify_date, sizeof(time_buffer), time_buffer)); | 1844 fprintf(f_output, "LAST-MOD:%s\n", pst_rfc2445_datetime_format(item->modify_date, sizeof(time_buffer), time_buffer)); |
1863 fprintf(f_output, "\n"); | 1895 fprintf(f_output, "\n"); |
1864 pst_free_recurrence(rdata); | 1896 pst_free_recurrence(rdata); |
1865 } | 1897 } |
1866 switch (appointment->label) { | 1898 switch (appointment->label) { |
1867 case PST_APP_LABEL_NONE: | 1899 case PST_APP_LABEL_NONE: |
1868 fprintf(f_output, "CATEGORIES:NONE\n"); | 1900 if (!write_extra_categories(f_output, item)) fprintf(f_output, "CATEGORIES:NONE\n"); |
1869 break; | 1901 break; |
1870 case PST_APP_LABEL_IMPORTANT: | 1902 case PST_APP_LABEL_IMPORTANT: |
1871 fprintf(f_output, "CATEGORIES:IMPORTANT\n"); | 1903 fprintf(f_output, "CATEGORIES:IMPORTANT\n"); |
1872 break; | 1904 break; |
1873 case PST_APP_LABEL_BUSINESS: | 1905 case PST_APP_LABEL_BUSINESS: |