comparison src/readpst.c @ 195:320cfcba8058

add python module interface to the shared library for easy scripting. the shared library must never write to stdout or stderr. fix pst_attach_to_mem so the caller does not need to initialize the buffer pointer.
author Carl Byington <carl@five-ten-sg.com>
date Mon, 20 Apr 2009 19:39:26 -0700
parents 4b498fd68464
children 07ceebd115ce
comparison
equal deleted inserted replaced
194:885b47107036 195:320cfcba8058
784 } 784 }
785 DEBUG_EMAIL(("Saving attachment to %s\n", temp)); 785 DEBUG_EMAIL(("Saving attachment to %s\n", temp));
786 if (!(fp = fopen(temp, "w"))) { 786 if (!(fp = fopen(temp, "w"))) {
787 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); 787 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
788 } else { 788 } else {
789 if (attach->data.data) 789 (void)pst_attach_to_file(pst, attach, fp);
790 pst_fwrite(attach->data.data, (size_t)1, attach->data.size, fp);
791 else {
792 (void)pst_attach_to_file(pst, attach, fp);
793 }
794 fclose(fp); 790 fclose(fp);
795 } 791 }
796 if (temp) free(temp); 792 if (temp) free(temp);
797 DEBUG_RET(); 793 DEBUG_RET();
798 } 794 }
827 823
828 824
829 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst) 825 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst)
830 { 826 {
831 char *attach_filename; 827 char *attach_filename;
832 char *enc = NULL; // base64 encoded attachment
833 DEBUG_ENT("write_inline_attachment"); 828 DEBUG_ENT("write_inline_attachment");
834 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id)); 829 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id));
835 if (attach->data.data) { 830
836 enc = pst_base64_encode (attach->data.data, attach->data.size); 831 if (!attach->data.data) {
837 if (!enc) {
838 DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n"));
839 DEBUG_RET();
840 return;
841 }
842 }
843 else {
844 // make sure we can fetch data from the id 832 // make sure we can fetch data from the id
845 pst_index_ll *ptr = pst_getID(pst, attach->i_id); 833 pst_index_ll *ptr = pst_getID(pst, attach->i_id);
846 if (!ptr) { 834 if (!ptr) {
847 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n")); 835 DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n"));
848 DEBUG_RET(); 836 DEBUG_RET();
865 fprintf(f_output, "Content-Disposition: inline\n\n"); 853 fprintf(f_output, "Content-Disposition: inline\n\n");
866 } else { 854 } else {
867 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach_filename); 855 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach_filename);
868 } 856 }
869 857
870 if (attach->data.data) { 858 (void)pst_attach_to_file_base64(pst, attach, f_output);
871 pst_fwrite(enc, 1, strlen(enc), f_output);
872 DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc)));
873 free(enc); // caught by valgrind
874 } else {
875 (void)pst_attach_to_file_base64(pst, attach, f_output);
876 }
877 fprintf(f_output, "\n\n"); 859 fprintf(f_output, "\n\n");
878 DEBUG_RET(); 860 DEBUG_RET();
879 } 861 }
880 862
881 863