CONST PROGRAM$ = "mkMulti" CONST REVISION$ = "0.20 (05/28/2002)" #define MAXNUM 4096 INCLUDE "const.oph" INCLUDE "buffer.oxh" INCLUDE "MailHelper.OXH" DECLARE EXTERNAL REM PROCs defined in XJMail EXTERNAL ChangeFolder:(folder$, msg&) EXTERNAL RefreshFolder:(folder$) REM PROC defined in this module EXTERNAL MkMultiCheckMHversion&: #define esc_dialog(message) \ dINIT message: \ dButtons "OK", &0d: \ DIALOG PROC Import: LOCAL source_file$(255), target_file$(255) LOCAL multi_head$(255), multi_boundary$(255), multi_type$(3, 255) LOCAL multi_enc$(2, 255), multi_disposition$(255) LOCAL ret&, i%, j&, crlf&, chk%, type_sw% LOCAL p_read&, a_tmp%(4), p_enc&, p_buff&, tmp$(255) LOCAL bufferlen&, headerlen& LOCAL source_hd%, target_hd%, org_hd% EXTERNAL currentfolder$, current_msg& IF MkMultiCheckMHversion&:=0 RETURN ENDIF crlf& = &0a0d multi_boundary$ = "--Next_Part(" \ + NUM$(HOUR, 2) + ":" + NUM$(MINUTE, 2) + ":" \ + NUM$(SECOND, 2) + "_" \ + NUM$(YEAR, 4) + "_" + NUM$(MONTH, 2) + NUM$(DAY, 2) \ + ")--" multi_enc$(1) = "Content-Transfer-Encoding: 7bit" + CHR$($0d) + CHR$($0a) multi_enc$(2) = "Content-Transfer-Encoding: base64" + CHR$($0d) + CHR$($0a) \ + "Content-Disposition: attachment; filename=" multi_head$ = "Mime-Version: 1.0" + CHR$($0d) + CHR$($0a) \ + "Content-Type: multipart/mixed; boundary=" + CHR$($22) \ + multi_boundary$ + CHR$($22) + CHR$($0d) + CHR$($0a) \ + multi_enc$(1) multi_type$(1) = "Content-Type: text/plain; charset=iso-2022-jp" \ + CHR$($0d) + CHR$($0a) + multi_enc$(1) + CHR$($0d) + CHR$($0a) multi_type$(2) = "Content-Type: application/octet-stream" + CHR$($0d) + CHR$($0a) multi_type$(3) = "Content-Type: image/" multi_boundary$ = "--" + multi_boundary$ p_read& = ALLOC(3 * MAXNUM) p_enc& = ALLOC(4 * MAXNUM + 512) p_buff& = ALLOC(4 * MAXNUM) IF RIGHT$(currentfolder$, 6) <> "draft\" AND RIGHT$(currentfolder$, 4) <> "out\" esc_dialog("Use at 'draft' or 'out' folder.") GOTO finish0:: ENDIF target_file$ = currentfolder$ + LEFT$("0000", 4 - LEN(NUM$(current_msg&, 4))) \ + NUM$(current_msg& + 1, 4) IF EXIST(target_file$) IF EXIST(target_file$ + ".org") dINIT target_file$ + ".org file exist." dTEXT "", "Overwrite ?" dBUTTONS "Yes", %Y OR $300, "No", %N OR $300 IF DIALOG <> 121 // y GOTO finish0:: ENDIF DELETE target_file$ + ".org" ENDIF COPY target_file$, target_file$ + ".org" ELSE esc_dialog("Not exist the target file.") GOTO finish0:: ENDIF chk% = 0 dINIT PROGRAM$ + " Rev. " + REVISION$ dFILE source_file$, "Attached file,Folder,Disk", 0 dCHECKBOX chk%, "Leave Backup File" IF DIALOG = 0 DELETE target_file$ + ".org" GOTO finish0:: ENDIF IF IOOPEN(source_hd%, source_file$, \ KIoOpenModeOpen% OR KIoOpenFormatBinary%) < 0 DELETE target_file$ + ".org" esc_dialog("Can't Open the attached file.") GOTO finish0:: ENDIF IF IOOPEN(target_hd%, target_file$, \ KIoOpenModeReplace% OR KIoOpenFormatBinary% \ OR KIoOpenAccessUpdate%) < 0 esc_dialog("Can't create the new target file.") IOCLOSE(source_hd%) GOTO finish0:: ENDIF IF IOOPEN(org_hd%, target_file$ + ".org", \ KIoOpenModeOpen% OR KIoOpenFormatBinary%) < 0 esc_dialog("Can't open the backuped target file.") IOCLOSE(source_hd%) IOCLOSE(target_hd%) GOTO finish0:: ENDIF tmp$ = UPPER$(RIGHT$(source_file$, 4)) IF tmp$ = ".JPG" multi_type$(3) += "jpeg" + CHR$($0d) + CHR$($0a) type_sw% = 1 ELSEIF tmp$ = ".GIF" multi_type$(3) += "gif" + CHR$($0d) + CHR$($0a) type_sw% = 1 ELSE type_sw% = 0 ENDIF i% = LEN(source_file$) WHILE PEEKB(ADDR(source_file$) + i%) <> $5C AND i% > 0 i%-- ENDWH IF i% > 0 multi_enc$(2) += RIGHT$(source_file$, LEN(source_file$) - i%) \ + CHR$($0d) + CHR$($0a) ENDIF bufferlen& = IOREAD(org_hd%, p_buff&, 4 * MAXNUM) headerlen& = BufferFind&:(p_buff&, bufferlen&, \ CHR$($0d)+CHR$($0a)+"----"+CHR$($0d)+CHR$($0a), 0) IF headerlen& < 0 esc_dialog("Can't find a header for XJMail.") IOCLOSE(org_hd%) IOCLOSE(target_hd%) IOCLOSE(source_hd%) GOTO finish0:: ENDIF BUSY "Busy", KBusyBottomLeft% IOWRITE(target_hd%, p_buff&, headerlen& + 2) IOWRITE(target_hd%, ADDR(multi_head$) + 1, LEN(multi_head$)) IOWRITE(target_hd%, p_buff& + headerlen& + 2, 6) IOWRITE(target_hd%, ADDR(multi_boundary$) + 1, LEN(multi_boundary$)) IOWRITE(target_hd%, ADDR(crlf&), 2) IOWRITE(target_hd%, ADDR(multi_type$(1)) + 1, LEN(multi_type$(1))) IOWRITE(target_hd%, p_buff& + headerlen& + 8, bufferlen& - headerlen& - 8) bufferlen& = IOREAD(org_hd%, p_buff&, 4 * MAXNUM) WHILE bufferlen& > 0 IOWRITE(target_hd%, p_buff&, bufferlen&) bufferlen& = IOREAD(org_hd%, p_buff&, 4 * MAXNUM) ENDWH IOWRITE(target_hd%, ADDR(crlf&), 2) IOWRITE(target_hd%, ADDR(multi_boundary$) + 1, LEN(multi_boundary$)) IOWRITE(target_hd%, ADDR(crlf&), 2) IF type_sw% = 0 IOWRITE(target_hd%, ADDR(multi_type$(2)) + 1, LEN(multi_type$(2))) ELSE IOWRITE(target_hd%, ADDR(multi_type$(3)) + 1, LEN(multi_type$(3))) ENDIF IOWRITE(target_hd%, ADDR(multi_enc$(2)) + 1, LEN(multi_enc$(2))) IOWRITE(target_hd%, ADDR(crlf&), 2) ret& = IOREAD(source_hd%, p_read&, 3 * MAXNUM) WHILE ret& > 0 j& = MHBEncodeBuffer2&:(p_read&, ret&, p_enc&, 4 * MAXNUM + 512, KMHLineBreakCRLF%, 64) IOWRITE(target_hd%, p_enc&, j&) ret& = IOREAD(source_hd%, p_read&, 3 * MAXNUM) ENDWH multi_boundary$ = CHR$($0d) + CHR$($0a) \ + multi_boundary$ + "--" + CHR$($0d) + CHR$($0a) IOWRITE(target_hd%, ADDR(multi_boundary$) + 1, LEN(multi_boundary$)) IOCLOSE(org_hd%) IOCLOSE(target_hd%) IOCLOSE(source_hd%) IF chk% = 0 DELETE target_file$ + ".org" ENDIF BUSY OFF RefreshFolder:(currentfolder$) ChangeFolder:(currentfolder$, -1) finish0:: FREEALLOC(p_read&) FREEALLOC(p_enc&) FREEALLOC(p_buff&) ENDP PROC MkMultiCheckMHversion&: REM Returns 1 if mailhelper.OPX Version>=1.03, 0 otherwise. LOCAL version&, verstr$(255) ONERR mkMultiOpxHaveNoVersion:: version&=MHOPXVersion&: ONERR OFF verstr$="$"+hex$(version&) GOTO mkMultiOpxVersionCommon:: mkMultiOpxHaveNoVersion:: REM The OPX has no MHOPXVersion&... it is older than $103 ONERR OFF version&=0 verstr$="(no MHOPXVersion&:)" mkMultiOpxVersionCommon:: IF version&>=$103 RETURN 1 ELSE dINIT "mkMulti error" dTEXT "mailhelper.OPX v1.03 or newer is needed","" dTEXT "current version: "+verstr$,"" dBUTTONS "OK", $0d DIALOG RETURN 0 ENDIF ENDP