コード例 #1
0
ファイル: utility.c プロジェクト: meetupcall/ytnef-2.6.1
void fprintUserProp(TNEFStruct TNEF, FILE *FPTR, DWORD PROPTYPE, DWORD PROPID, char TEXT[]) {
    variableLength *vl;
    if ((vl=MAPIFindUserProp(&(TNEF.MapiProperties), PROP_TAG(PROPTYPE, PROPID))) != MAPI_UNDEFINED) { 
        if (vl->size > 0)  
            if ((vl->size == 1) && (vl->data[0] == 0)) {
            } else { 
                fprintf(FPTR, TEXT, vl->data); 
            } 
    }
}
コード例 #2
0
ファイル: tnef-plugin.c プロジェクト: ebbywiselyn/evolution
void fprintUserProp(TNEFStruct *tnef, FILE *fptr, DWORD proptype, DWORD propid, char text[]) {
    variableLength *vl;
    if ((vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(proptype, propid))) != MAPI_UNDEFINED) {
        if (vl->size > 0) {
            if ((vl->size == 1) && (vl->data[0] == 0)) {
            } else {
                fprintf(fptr, text, vl->data);
            }
	}
    }
}
コード例 #3
0
ファイル: vtask.c プロジェクト: meetupcall/ytnef-2.6.1
void SaveVTask(TNEFStruct TNEF) {
    variableLength *vl;
    variableLength *filename;
    int index,i;
    char ifilename[256];
    char *charptr, *charptr2;
    dtr thedate;
    FILE *fptr;
    DDWORD *ddword_ptr;
    DDWORD ddword_val;
    
    vl = MAPIFindProperty(&(TNEF.MapiProperties), PROP_TAG(PT_STRING8, PR_CONVERSATION_TOPIC));

    if (vl == MAPI_UNDEFINED) {
        return;
    }

    index = strlen(vl->data);
    while (vl->data[index] == ' ') 
            vl->data[index--] = 0;

    if (filepath == NULL) {
        sprintf(ifilename, "%s.vcf", vl->data);
    } else {
        sprintf(ifilename, "%s/%s.vcf", filepath, vl->data);
    }
    for(i=0; i<strlen(ifilename); i++) 
        if (ifilename[i] == ' ') 
            ifilename[i] = '_';
    printf("%s\n", ifilename);

    if (savefiles == 0) return;

    if ((fptr = fopen(ifilename, "wb"))==NULL) {
            printf("Error writing file to disk!");
    } else {
        fprintf(fptr, "BEGIN:VCALENDAR\n");
        fprintf(fptr, PRODID);
        fprintf(fptr, "VERSION:2.0\n");
        fprintf(fptr, "METHOD:PUBLISH\n");
        filename = NULL;

        fprintf(fptr, "BEGIN:VTODO\n");
        if (TNEF.messageID[0] != 0) {
            fprintf(fptr,"UID:%s\n", TNEF.messageID);
        }
        filename = MAPIFindUserProp(&(TNEF.MapiProperties), \
                        PROP_TAG(PT_STRING8, 0x8122));
        if (filename != MAPI_UNDEFINED) {
            fprintf(fptr, "ORGANIZER:%s\n", filename->data);
        }
                 

        if ((filename = MAPIFindProperty(&(TNEF.MapiProperties), PROP_TAG(PT_STRING8, PR_DISPLAY_TO))) != MAPI_UNDEFINED) {
            filename = MAPIFindUserProp(&(TNEF.MapiProperties), PROP_TAG(PT_STRING8, 0x811f));
        }
        if ((filename != MAPI_UNDEFINED) && (filename->size > 1)) {
            charptr = filename->data-1;
            charptr2=strstr(charptr+1, ";");
            while (charptr != NULL) {
                charptr++;
                charptr2 = strstr(charptr, ";");
                if (charptr2 != NULL) {
                    *charptr2 = 0;
                }
                while (*charptr == ' ') 
                    charptr++;
                fprintf(fptr, "ATTENDEE;CN=%s;ROLE=REQ-PARTICIPANT:%s\n", charptr, charptr);
                charptr = charptr2;
            }
        }

        if (TNEF.subject.size > 0) {
            fprintf(fptr,"SUMMARY:");
            Cstylefprint(fptr,&(TNEF.subject));
            fprintf(fptr,"\n");
        }

        if (TNEF.body.size > 0) {
            fprintf(fptr,"DESCRIPTION:");
            Cstylefprint(fptr,&(TNEF.body));
            fprintf(fptr,"\n");
        }

        filename = MAPIFindProperty(&(TNEF.MapiProperties), \
                    PROP_TAG(PT_SYSTIME, PR_CREATION_TIME));
        if (filename != MAPI_UNDEFINED) {
            fprintf(fptr, "DTSTAMP:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n", 
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }

        filename = MAPIFindUserProp(&(TNEF.MapiProperties), \
                    PROP_TAG(PT_SYSTIME, 0x8517));
        if (filename != MAPI_UNDEFINED) {
            fprintf(fptr, "DUE:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n", 
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }
        filename = MAPIFindProperty(&(TNEF.MapiProperties), \
                    PROP_TAG(PT_SYSTIME, PR_LAST_MODIFICATION_TIME));
        if (filename != MAPI_UNDEFINED) {
            fprintf(fptr, "LAST-MODIFIED:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n", 
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }
        // Class
        filename = MAPIFindUserProp(&(TNEF.MapiProperties), \
                        PROP_TAG(PT_BOOLEAN, 0x8506));
        if (filename != MAPI_UNDEFINED) {
            ddword_ptr = (DDWORD*)filename->data;
            ddword_val = SwapDDWord((BYTE*)ddword_ptr);
            fprintf(fptr, "CLASS:" );
            if (*ddword_ptr == 1) {
                fprintf(fptr,"PRIVATE\n");
            } else {
                fprintf(fptr,"PUBLIC\n");
            }
        }
        fprintf(fptr, "END:VTODO\n");
        fprintf(fptr, "END:VCALENDAR\n");
        fclose(fptr);
    }

}
コード例 #4
0
ファイル: main.c プロジェクト: georox/ytnef
void PrintTNEF(TNEFStruct TNEF) {
    int index,i;
    int j, object;
    int count;
    FILE *fptr;
    char ifilename[256];
    char *charptr, *charptr2;
    DDWORD ddword_tmp;
    int SaveFile;
    DDWORD *ddword_ptr;
    MAPIProps mapip;
    variableLength *filename;
    variableLength *filedata;
    Attachment *p;
    TNEFStruct emb_tnef;

    printf("---> In %s format\n", TNEF.version);
    if (TNEF.from.size > 0) 
        printf("From: %s\n", TNEF.from.data);
    if (TNEF.subject.size > 0) 
        printf("Subject: %s\n", TNEF.subject.data);
    if (TNEF.priority[0] != 0) 
        printf("Message Priority: %s\n", TNEF.priority);
    if (TNEF.dateSent.wYear >0) {
        printf("Date Sent: ");
        TNEFPrintDate(TNEF.dateSent);
        printf("\n");
    }
    if (TNEF.dateReceived.wYear >0) {
        printf("Date Received: ");
        TNEFPrintDate(TNEF.dateReceived);
        printf("\n");
    }
    if (TNEF.messageStatus[0] != 0) 
        printf("Message Status: %s\n", TNEF.messageStatus);
    if (TNEF.messageClass[0] != 0)  {
        printf("Message Class: %s\n", TNEF.messageClass);
        if (strcmp(TNEF.messageClass, "IPM.Contact") == 0) {
            printf("--> Found a contact card\n");
        }
        if (strcmp(TNEF.messageClass, "IPM.Task") == 0) {
            printf("--> Found a Task Entry\n");
        }
    }

    if (TNEF.OriginalMessageClass.size >0) 
        printf("Original Message Class: %s\n", 
                    TNEF.OriginalMessageClass.data);
    if (TNEF.messageID[0] != 0) 
        printf("Message ID: %s\n", TNEF.messageID);
    if (TNEF.parentID[0] != 0) 
        printf("Parent ID: %s\n", TNEF.parentID);
    if (TNEF.conversationID[0] != 0) 
        printf("Conversation ID: %s\n", TNEF.conversationID);
    if (TNEF.DateStart.wYear >0) {
        printf("Start Date: ");
        TNEFPrintDate(TNEF.DateStart);
        printf("\n");
    }
    if (TNEF.DateEnd.wYear > 0) {
        printf("End Date: ");
        TNEFPrintDate(TNEF.DateEnd);
        printf("\n");
    }
    if (TNEF.Owner.size > 0 ) 
        printf("Owner: %s\n", TNEF.Owner.data);

    if (TNEF.Delegate.size > 0) 
        printf("Delegate: %s\n", TNEF.Delegate.data);

    if (TNEF.AidOwner.size > 0) 
        printf("Aid Owner: %s\n", TNEF.AidOwner.data);


    if (TNEF.body.size>0) 
        printf("-- Message Body (%i bytes) --\n%s\n-- End Body --\n", 
                TNEF.body.size, TNEF.body.data); 
        
    if (TNEF.MapiProperties.count > 0) {
        printf("    MAPI Properties: %i\n", TNEF.MapiProperties.count);
        MAPIPrint(&TNEF.MapiProperties);
    }

    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties), 
                        PROP_TAG(PT_STRING8,0x24))) != MAPI_UNDEFINED) {
        if (strcmp(filename->data, "IPM.Appointment") == 0) {
            printf("--> Found an appointment entry\n");
        }
    }

    // Now Print file data
    p = TNEF.starting_attach.next;
    count = 0;
    while (p != NULL) {
        count++;
        printf("[%i] [", count);
        switch (p->RenderData.atyp) {
            case 0: printf("NULL      "); break;
            case 1: printf("File      "); break;
            case 2: printf("OLE Object"); break;
            case 3: printf("Picture   "); break;
            case 4: printf("Max       "); break;
            default:printf("Unknown   "); 
        }
        printf("] ");
        if (p->Title.size > 0) 
            printf("%s", p->Title.data);
        printf("\n");
        if (p->RenderData.dwFlags == 0x00000001) 
            printf("     MAC Binary Encoding\n");

        if (p->TransportFilename.size >0) 
            printf("     Transported under the name %s\n", 
                    p->TransportFilename.data);

        if (p->Date.wYear >0 ) {
            printf("    Date: ");
            TNEFPrintDate(p->Date);
            printf("\n");
        }
        if (p->CreateDate.wYear > 0) {
            printf("    Creation Date: ");
            TNEFPrintDate(p->CreateDate);
            printf("\n");
        }
        if (p->ModifyDate.wYear > 0) {
            printf("    Modified on: ");
            TNEFPrintDate(p->ModifyDate);
            printf("\n");
        }

        if (p->MAPI.count>0) {
            printf("    MAPI Properties: %i\n", p->MAPI.count);
            if (verbose == 1) {
                MAPIPrint(&p->MAPI);
            }
        }

        if (p->FileData.size > 0) {
            printf("    Attachment Size:  %ib\n", p->FileData.size);
            
            if ((filename = MAPIFindProperty(&(p->MAPI), PROP_TAG(30,0x3707))) == MAPI_UNDEFINED) {
                if ((filename = MAPIFindProperty(&(p->MAPI), PROP_TAG(30,0x3001))) == MAPI_UNDEFINED) {
                    filename = &(p->Title);
                }
            }


            object = 1;           
            if((filedata = MAPIFindProperty(&(p->MAPI), 
                                    PROP_TAG(PT_OBJECT, PR_ATTACH_DATA_OBJ))) 
                    == MAPI_UNDEFINED) {
                if((filedata = MAPIFindProperty(&(p->MAPI), 
                                    PROP_TAG(PT_BINARY, PR_ATTACH_DATA_OBJ))) 
                        == MAPI_UNDEFINED) {
                    filedata = &(p->FileData);
                    object = 0;
                }
            }
            sprintf(ifilename, "%s", filename->data);
            for(i=0; i<strlen(ifilename); i++) 
                if (ifilename[i] == ' ') 
                    ifilename[i] = '_';
            printf("    File saves as [%s]\n", ifilename);
        }
        p=p->next;
    }
}
コード例 #5
0
ファイル: tnef_parse.c プロジェクト: kuba-moo/claws-mail
static gboolean tnef_parse (MimeParser *parser, MimeInfo *mimeinfo)
{
	TNEFStruct *tnef;
	MimeInfo *sub_info = NULL;
	variableLength *tmp_var;
	Attachment *att;
	int parse_result = 0;
	gboolean cal_done = FALSE;

	if (!procmime_decode_content(mimeinfo)) {
		debug_print("error decoding\n");
		return FALSE;
	}
	debug_print("Tnef parser parsing part (%d).\n", mimeinfo->length);
	if (mimeinfo->content == MIMECONTENT_FILE)
		debug_print("content: %s\n", mimeinfo->data.filename);
	else 
		debug_print("contents in memory (len %zd)\n", 
			strlen(mimeinfo->data.mem));
	
	tnef = g_new0(TNEFStruct, 1);
	TNEFInitialize(tnef);

	tnef->Debug = debug_get_mode();

	if (mimeinfo->content == MIMECONTENT_MEM)
		parse_result = TNEFParseMemory(mimeinfo->data.mem, mimeinfo->length, tnef);
	else
		parse_result = TNEFParseFile(mimeinfo->data.filename, tnef);
	
	mimeinfo->type = MIMETYPE_MULTIPART;
	mimeinfo->subtype = g_strdup("mixed");
	g_hash_table_insert(mimeinfo->typeparameters,
			    g_strdup("description"),
			    g_strdup("Parsed from MS-TNEF"));

	if (parse_result != 0) {
		g_warning("Failed to parse TNEF data.");
		TNEFFree(tnef);
		return FALSE;
	}
	
	sub_info = NULL;
	if (tnef->messageClass[0] != '\0') {
		if (strcmp(tnef->messageClass, "IPM.Contact") == 0)
			sub_info = tnef_parse_vcard(tnef);
		else if (strcmp(tnef->messageClass, "IPM.Task") == 0)
			sub_info = tnef_parse_vtask(tnef);
		else if (strcmp(tnef->messageClass, "IPM.Appointment") == 0) {
			sub_info = tnef_parse_vcal(tnef);
			cal_done = TRUE;
		}
	}

	if (sub_info)
		g_node_append(mimeinfo->node, sub_info->node);
	sub_info = NULL;

	if (tnef->MapiProperties.count > 0) {
		tmp_var = MAPIFindProperty (&(tnef->MapiProperties), PROP_TAG(PT_BINARY,PR_RTF_COMPRESSED));
		if (tmp_var != MAPI_UNDEFINED) {
			sub_info = tnef_parse_rtf(tnef, tmp_var);
		}
	}

	if (sub_info)
		g_node_append(mimeinfo->node, sub_info->node);
	sub_info = NULL;

	tmp_var = MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8,0x24));
	if (tmp_var != MAPI_UNDEFINED) {
		if (!cal_done && strcmp(tmp_var->data, "IPM.Appointment") == 0) {
			sub_info = tnef_parse_vcal(tnef);
		}
	}
	
	if (sub_info)
		g_node_append(mimeinfo->node, sub_info->node);
	sub_info = NULL;

	att = tnef->starting_attach.next;
	while (att) {
		gchar *filename = NULL;
		gboolean is_object = TRUE;
		DWORD signature;

		tmp_var = MAPIFindProperty(&(att->MAPI), PROP_TAG(30,0x3707));
		if (tmp_var == MAPI_UNDEFINED)
			tmp_var = MAPIFindProperty(&(att->MAPI), PROP_TAG(30,0x3001));
		if (tmp_var == MAPI_UNDEFINED)
			tmp_var = &(att->Title);

		if (tmp_var->data)
			filename = g_strdup(tmp_var->data);
		
		tmp_var = MAPIFindProperty(&(att->MAPI), PROP_TAG(PT_OBJECT, PR_ATTACH_DATA_OBJ));
		if (tmp_var == MAPI_UNDEFINED)
			tmp_var = MAPIFindProperty(&(att->MAPI), PROP_TAG(PT_BINARY, PR_ATTACH_DATA_OBJ));
		if (tmp_var == MAPI_UNDEFINED) {
			tmp_var = &(att->FileData);
			is_object = FALSE;
		}
		
		sub_info = tnef_dump_file(filename, 
			tmp_var->data + (is_object ? 16:0), 
			tmp_var->size - (is_object ? 16:0));
		
		if (sub_info)
			g_node_append(mimeinfo->node, sub_info->node);
	
		memcpy(&signature, tmp_var->data+(is_object ? 16:0), sizeof(DWORD));

		if (TNEFCheckForSignature(signature) == 0) {
			debug_print("that's TNEF stuff, process it\n");
			tnef_parse(parser, sub_info);
		}

		sub_info = NULL;
		
		att = att->next;

		g_free(filename);
	}
	
	TNEFFree(tnef);
	return TRUE;
}
コード例 #6
0
ファイル: vcal.c プロジェクト: Yeraze/ytnef
void SaveVCalendar(TNEFStruct TNEF, int isMtgReq) {
  char ifilename[MAX_FILENAME_SIZE];
  variableLength *filename;
  char *charptr, *charptr2;
  FILE *fptr;
  int index;
  DDWORD *ddword_ptr;
  dtr thedate;

  if(isMtgReq) {
    CreateUniqueFilename(ifilename, MAX_FILENAME_SIZE, "MtgReq", "ics", filepath);
  } else {
    CreateUniqueFilename(ifilename, MAX_FILENAME_SIZE, "calendar", "ics", filepath);
  }

  printf("%s\n", ifilename);
  if (savefiles == 0)
    return;

  if ((fptr = fopen(ifilename, "wb")) == NULL) {
    printf("Error writing file to disk!");
  } else {
    fprintf(fptr, "BEGIN:VCALENDAR\n");
    if (TNEF.messageClass[0] != 0) {
      charptr2 = TNEF.messageClass;
      charptr = charptr2;
      while (*charptr != 0) {
        if (*charptr == '.') {
          charptr2 = charptr;
        }
        charptr++;
      }
      if (strcmp((char*)charptr2, ".MtgCncl") == 0) {
        fprintf(fptr, "METHOD:CANCEL\n");
      } else {
        fprintf(fptr, "METHOD:REQUEST\n");
      }
    } else {
      fprintf(fptr, "METHOD:REQUEST\n");
    }
    fprintf(fptr, PRODID);
    fprintf(fptr, "VERSION:2.0\n");
    fprintf(fptr, "BEGIN:VEVENT\n");

    // UID
    // After alot of comparisons, I'm reasonably sure this is totally
    // wrong.  But it's not really necessary.
    //
    // I think it only exists to connect future modification entries to
    // this entry. so as long as it's incorrectly interpreted the same way
    // every time, it should be ok :)
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_BINARY, 0x3))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_BINARY, 0x23))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      fprintf(fptr, "UID:");
      for (index = 0; index < filename->size; index++) {
        fprintf(fptr, "%02X", (unsigned char)filename->data[index]);
      }
      fprintf(fptr, "\n");
    }

    // Sequence
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_LONG, 0x8201))) != MAPI_UNDEFINED) {
      ddword_ptr = (DDWORD *)filename->data;
      fprintf(fptr, "SEQUENCE:%i\n", (int) *ddword_ptr);
    }

    filename = NULL;
    if ((filename = MAPIFindProperty(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_BINARY, PR_SENDER_SEARCH_KEY)))
        == MAPI_UNDEFINED) {
      if ((filename = MAPIFindProperty(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_UNICODE, PR_SENT_REPRESENTING_EMAIL_ADDRESS)))
          == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      charptr = (char*)filename->data;
      charptr2 = (char*)strstr((char*)charptr, ":");
      if (charptr2 == NULL)
        charptr2 = charptr;
      else
        charptr2++;
      fprintf(fptr, "ORGANIZER;CN=\"%s\":MAILTO:%s\n",
              charptr2, charptr2);
    }

    // Required Attendees
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_STRING8, 0x823b))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_UNICODE, 0x823b))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      // We have a list of required participants, so
      // write them out.
      if (strlen((char*)filename->data) > 1) {
        charptr = (char*)filename->data - 1;
        charptr2 = (char*)strstr((char*)(charptr + 1), ";");
        while (charptr != NULL) {
          charptr++;
          charptr2 = (char *)strstr((char*)charptr, ";");
          if (charptr2 != NULL) {
            *charptr2 = 0;
          }
          while (*charptr == ' ')
            charptr++;
          fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
          fprintf(fptr, "ROLE=REQ-PARTICIPANT;RSVP=TRUE;");
          fprintf(fptr, "CN=\"%s\":MAILTO:%s\n",
                  charptr, charptr);
          charptr = charptr2;
        }
      }
      // Optional attendees
      filename = NULL;
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_STRING8, 0x823c))) == MAPI_UNDEFINED) {
        if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                         PROP_TAG(PT_UNICODE, 0x823c))) == MAPI_UNDEFINED) {
          filename = NULL;
        }
      }
      if (filename != NULL) {
        // The list of optional participants
        if (strlen((char*)filename->data) > 1) {
          charptr = (char*)filename->data - 1;
          charptr2 = (char *)strstr((char*)(charptr + 1), ";");
          while (charptr != NULL) {
            charptr++;
            charptr2 = (char *)strstr((char*)charptr, ";");
            if (charptr2 != NULL) {
              *charptr2 = 0;
            }
            while (*charptr == ' ')
              charptr++;
            fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
            fprintf(fptr, "ROLE=OPT-PARTICIPANT;RSVP=TRUE;");
            fprintf(fptr, "CN=\"%s\":MAILTO:%s\n",
                    charptr, charptr);
            charptr = charptr2;
          }
        }
      }
    } else {
      filename = NULL;
      if ((filename=MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_STRING8, 0x8238))) == MAPI_UNDEFINED) {
        if ((filename=MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_UNICODE, 0x8238))) == MAPI_UNDEFINED) {
          filename = NULL;
        }
      }
      if (filename != NULL) {
        if (strlen((char*)filename->data) > 1) {
          charptr = (char*)filename->data - 1;
          charptr2 = (char *)strstr((char*)(charptr + 1), ";");
          while (charptr != NULL) {
            charptr++;
            charptr2 = (char *)strstr((char*)charptr, ";");
            if (charptr2 != NULL) {
              *charptr2 = 0;
            }
            while (*charptr == ' ')
              charptr++;
            fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
            fprintf(fptr, "ROLE=REQ-PARTICIPANT;RSVP=TRUE;");
            fprintf(fptr, "CN=\"%s\":MAILTO:%s\n", charptr, charptr);
            charptr = charptr2;
          }
        }
      }
    }
    // Summary
    filename = NULL;
    if ((filename = MAPIFindProperty(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_STRING8, PR_CONVERSATION_TOPIC))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindProperty(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_UNICODE, PR_CONVERSATION_TOPIC))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      fprintf(fptr, "SUMMARY:");
      Cstylefprint(fptr, filename);
      fprintf(fptr, "\n");
    }

    // Description
    if ((filename = MAPIFindProperty(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_BINARY, PR_RTF_COMPRESSED)))
        != MAPI_UNDEFINED) {
      variableLength buf;
      if ((buf.data = DecompressRTF(filename, &(buf.size))) != NULL) {
        fprintf(fptr, "DESCRIPTION:");
        PrintRTF(fptr, &buf);
        free(buf.data);
      }

    }

    // Location
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_STRING8, 0x0002))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_STRING8, 0x8208))) == MAPI_UNDEFINED) {
        if ((filename=MAPIFindUserProp(&(TNEF.MapiProperties), 
                                       PROP_TAG(PT_UNICODE, 0x0002))) == MAPI_UNDEFINED) {
          if ((filename=MAPIFindUserProp(&(TNEF.MapiProperties), 
                                         PROP_TAG(PT_UNICODE, 0x8208))) == MAPI_UNDEFINED) {
            filename = NULL;
          }
        }
      }
    }
    if (filename != NULL) {
      fprintf(fptr, "LOCATION: %s\n", filename->data);
    }
    // Date Start
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_SYSTIME, 0x820d))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_SYSTIME, 0x8516))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      fprintf(fptr, "DTSTART:");
      MAPISysTimetoDTR(filename->data, &thedate);
      fprintf(fptr, "%04i%02i%02iT%02i%02i%02iZ\n",
              thedate.wYear, thedate.wMonth, thedate.wDay,
              thedate.wHour, thedate.wMinute, thedate.wSecond);
    }
    // Date End
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_SYSTIME, 0x820e))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_SYSTIME, 0x8517))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }
    if (filename != NULL) {
      fprintf(fptr, "DTEND:");
      MAPISysTimetoDTR(filename->data, &thedate);
      fprintf(fptr, "%04i%02i%02iT%02i%02i%02iZ\n",
              thedate.wYear, thedate.wMonth, thedate.wDay,
              thedate.wHour, thedate.wMinute, thedate.wSecond);
    }
    // Date Stamp
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_SYSTIME, 0x8202))) == MAPI_UNDEFINED) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_SYSTIME, 0x001a))) == MAPI_UNDEFINED) {
        filename = NULL;
      }
    }

    if (filename != NULL){
      fprintf(fptr, "DTSTAMP:");
      MAPISysTimetoDTR(filename->data, &thedate);
      fprintf(fptr, "%04i%02i%02iT%02i%02i%02iZ\n",
              thedate.wYear, thedate.wMonth, thedate.wDay,
              thedate.wHour, thedate.wMinute, thedate.wSecond);
    }
    // Class
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_BOOLEAN, 0x8506))) != MAPI_UNDEFINED) {
      ddword_ptr = (DDWORD *)filename->data;
      fprintf(fptr, "CLASS:");
      if (*ddword_ptr == 1) {
        fprintf(fptr, "PRIVATE\n");
      } else {
        fprintf(fptr, "PUBLIC\n");
      }
    }
    // Recurrence
    filename = NULL;
    if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                     PROP_TAG(PT_BINARY, 0x8216))) != MAPI_UNDEFINED) {
      PrintRrule(fptr, (char*)filename->data, filename->size, TNEF);
    }

    // Wrap it up
    fprintf(fptr, "END:VEVENT\n");
    fprintf(fptr, "END:VCALENDAR\n");
    fclose(fptr);
  }
}
コード例 #7
0
ファイル: vcal.c プロジェクト: Yeraze/ytnef
void PrintRrule(FILE *fptr, char *recur_data, int size, TNEFStruct TNEF) {
  variableLength *filename;

  if (size < 0x1F) {
    return;
  }

  fprintf(fptr, "RRULE:FREQ=");

  if (recur_data[0x04] == 0x0A) {
    fprintf(fptr, "DAILY");

    if (recur_data[0x16] == 0x23 || recur_data[0x16] == 0x22 ||
        recur_data[0x16] == 0x21) {
      if ((filename = MAPIFindUserProp(&(TNEF.MapiProperties),
                                       PROP_TAG(PT_I2, 0x0011))) != MAPI_UNDEFINED) {
        fprintf(fptr, ";INTERVAL=%d", *(filename->data));
      }
      if (recur_data[0x16] == 0x22 || recur_data[0x16] == 0x21) {
        fprintf(fptr, ";COUNT=%d",
                GetRruleCount(recur_data[0x1B], recur_data[0x1A]));
      }
    } else if (recur_data[0x16] == 0x3E) {
      fprintf(fptr, ";BYDAY=MO,TU,WE,TH,FR");
      if (recur_data[0x1A] == 0x22 || recur_data[0x1A] == 0x21) {
        fprintf(fptr, ";COUNT=%d",
                GetRruleCount(recur_data[0x1F], recur_data[0x1E]));
      }
    }
  } else if (recur_data[0x04] == 0x0B) {
    fprintf(fptr, "WEEKLY;INTERVAL=%d;BYDAY=%s",
            recur_data[0x0E], GetRruleDayname(recur_data[0x16]));
    if (recur_data[0x1A] == 0x22 || recur_data[0x1A] == 0x21) {
      fprintf(fptr, ";COUNT=%d",
              GetRruleCount(recur_data[0x1F], recur_data[0x1E]));
    }
  } else if (recur_data[0x04] == 0x0C) {
    fprintf(fptr, "MONTHLY");
    if (recur_data[0x06] == 0x02) {
      fprintf(fptr, ";INTERVAL=%d;BYMONTHDAY=%d", recur_data[0x0E],
              recur_data[0x16]);
      if (recur_data[0x1A] == 0x22 || recur_data[0x1A] == 0x21) {
        fprintf(fptr, ";COUNT=%d", GetRruleCount(recur_data[0x1F],
                recur_data[0x1E]));
      }
    } else if (recur_data[0x06] == 0x03) {
      fprintf(fptr, ";BYDAY=%s;BYSETPOS=%d;INTERVAL=%d",
              GetRruleDayname(recur_data[0x16]),
              recur_data[0x1A] == 0x05 ? -1 : recur_data[0x1A],
              recur_data[0x0E]);
      if (recur_data[0x1E] == 0x22 || recur_data[0x1E] == 0x21) {
        fprintf(fptr, ";COUNT=%d", GetRruleCount(recur_data[0x23],
                recur_data[0x22]));
      }
    }
  } else if (recur_data[0x04] == 0x0D) {
    fprintf(fptr, "YEARLY;BYMONTH=%d",
            GetRruleMonthNum(recur_data[0x0A], recur_data[0x0B]));
    if (recur_data[0x06] == 0x02) {
      fprintf(fptr, ";BYMONTHDAY=%d", recur_data[0x16]);
    } else if (recur_data[0x06] == 0x03) {
      fprintf(fptr, ";BYDAY=%s;BYSETPOS=%d",
              GetRruleDayname(recur_data[0x16]),
              recur_data[0x1A] == 0x05 ? -1 : recur_data[0x1A]);
    }
    if (recur_data[0x1E] == 0x22 || recur_data[0x1E] == 0x21) {
      fprintf(fptr, ";COUNT=%d", GetRruleCount(recur_data[0x23],
              recur_data[0x22]));
    }
  }
  fprintf(fptr, "\n");
}
コード例 #8
0
ECRESULT ECUserStoreTable::QueryRowData(ECGenericObjectTable *lpThis, struct soap *soap, ECSession *lpSession, ECObjectTableList* lpRowList, struct propTagArray *lpsPropTagArray, void* lpObjectData, struct rowSet **lppRowSet, bool bCacheTableData, bool bTableLimit)
{
	ECRESULT er = erSuccess;
	ECUserStoreTable *pThis = dynamic_cast<ECUserStoreTable*>(lpThis);
	struct rowSet *lpsRowSet = NULL;
	ECObjectTableList::iterator iterRowList;
	int i, k;
	GUID sZeroGuid = {0};

	if (!lpThis) {
		er = ZARAFA_E_INVALID_PARAMETER;
		goto exit;
	}

	lpsRowSet = s_alloc<rowSet>(soap);
	lpsRowSet->__size = 0;
	lpsRowSet->__ptr = NULL;

	if(lpRowList->empty()) {
		*lppRowSet = lpsRowSet;
		goto exit; // success
	}

	// We return a square array with all the values
	lpsRowSet->__size = lpRowList->size();
	lpsRowSet->__ptr = s_alloc<propValArray>(soap, lpsRowSet->__size);
	memset(lpsRowSet->__ptr, 0, sizeof(propValArray) * lpsRowSet->__size);

	// Allocate memory for all rows
	for (i = 0; i < lpsRowSet->__size; i++) {
		lpsRowSet->__ptr[i].__size = lpsPropTagArray->__size;
		lpsRowSet->__ptr[i].__ptr = s_alloc<propVal>(soap, lpsPropTagArray->__size);
		memset(lpsRowSet->__ptr[i].__ptr, 0, sizeof(propVal) * lpsPropTagArray->__size);
	}

	for (i = 0, iterRowList = lpRowList->begin(); iterRowList != lpRowList->end(); iterRowList++, i++) {
		for (k = 0; k < lpsPropTagArray->__size; k++) {

			lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]);
			lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul;
			lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND;

			switch (PROP_ID(lpsPropTagArray->__ptr[k])) {
			case PROP_ID(PR_INSTANCE_KEY):
				// generate key 
				lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin;
				lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PR_INSTANCE_KEY;
				lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap);
				lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(sObjectTableKey);
				lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(sObjectTableKey));
				memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (void*)&(*iterRowList), sizeof(sObjectTableKey));
				break;

			case PROP_ID(PR_EC_USERNAME):
				if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.empty()) {
					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA;
					lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.c_str());
				}
				break;
			case PROP_ID(PR_DISPLAY_NAME):
				if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.empty()) {
					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA;
					lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.c_str());
				}
				break;
			case PROP_ID(PR_EC_STOREGUID):
				if (pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid != sZeroGuid) {
					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin;
					lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap);
					lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(GUID);
					lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(GUID));
					memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (unsigned char*)&pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid, sizeof(GUID));
				}
				break;
			case PROP_ID(PR_EC_STORETYPE):
				lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

				lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul;
				lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulStoreType;
				break;
			case PROP_ID(PR_EC_COMPANYID):
				if (pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId != 0) {
					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul;
					lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId;
				}
				break;
			case PROP_ID(PR_EC_COMPANY_NAME):
				if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.empty()) {
					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];

					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA;
					lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.c_str());
				}
				break;
			case PROP_ID(PR_STORE_ENTRYID):
				// ignore errors
				ECGenProps::GetPropComputedUncached(soap, NULL ,lpSession, PR_STORE_ENTRYID, pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0,
							   				pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0, MAPI_STORE, &lpsRowSet->__ptr[i].__ptr[k]);
				break;
			case PROP_ID(PR_LAST_MODIFICATION_TIME):
				if (pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime != 0) {
					FILETIME ftTmp;
					UnixTimeToFileTime(pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime, &ftTmp);

					lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];
					lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_hilo;
					lpsRowSet->__ptr[i].__ptr[k].Value.hilo = s_alloc<struct hiloLong>(soap);
					lpsRowSet->__ptr[i].__ptr[k].Value.hilo->hi = ftTmp.dwHighDateTime;
					lpsRowSet->__ptr[i].__ptr[k].Value.hilo->lo = ftTmp.dwLowDateTime;
				}
				break;
			case PROP_ID(PR_MESSAGE_SIZE_EXTENDED):
				lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k];
				lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_li;
				lpsRowSet->__ptr[i].__ptr[k].Value.li = pThis->m_mapUserStoreData[iterRowList->ulObjId].ullStoreSize;
				break;
			default:
				lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]);

				lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul;
				lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND;
				break;
			};
		}
	}

	*lppRowSet = lpsRowSet;

exit:
	return er;
}
コード例 #9
0
ファイル: tnef-plugin.c プロジェクト: ebbywiselyn/evolution
void saveVCalendar(TNEFStruct *tnef) {
    char ifilename[256];
    variableLength *filename;
    char *charptr, *charptr2;
    FILE *fptr;
    int index;
    DDWORD *ddword_ptr;
    DDWORD ddword_val;
    dtr thedate;

    if (filepath == NULL) {
        sprintf(ifilename, "calendar.vcf");
    } else {
        sprintf(ifilename, "%s/calendar.vcf", filepath);
    }
    printf("%s\n", ifilename);

    if ((fptr = fopen(ifilename, "wb"))==NULL) {
            printf("Error writing file to disk!");
    } else {
        fprintf(fptr, "BEGIN:VCALENDAR\n");
        if (tnef->messageClass[0] != 0) {
            charptr2=tnef->messageClass;
            charptr=charptr2;
            while (*charptr != 0) {
                if (*charptr == '.') {
                    charptr2 = charptr;
                }
                charptr++;
            }
            if (strcmp(charptr2, ".MtgCncl") == 0) {
                fprintf(fptr, "METHOD:CANCEL\n");
            } else {
                fprintf(fptr, "METHOD:REQUEST\n");
            }
        } else {
            fprintf(fptr, "METHOD:REQUEST\n");
        }
        fprintf(fptr, "VERSION:2.0\n");
        fprintf(fptr, "BEGIN:VEVENT\n");

	/* UID
	   After alot of comparisons, I'm reasonably sure this is totally
	   wrong.  But it's not really necessary. */

	/* I think it only exists to connect future modification entries to
	   this entry. so as long as it's incorrectly interpreted the same way
	   every time, it should be ok :) */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_BINARY, 0x3))) == MAPI_UNDEFINED) {
            if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                            PROP_TAG(PT_BINARY, 0x23))) == MAPI_UNDEFINED) {
                filename = NULL;
            }
        }
        if (filename!=NULL) {
            fprintf(fptr, "UID:");
            for(index=0;index<filename->size;index++) {
                fprintf(fptr,"%02X", (unsigned char)filename->data[index]);
            }
            fprintf(fptr,"\n");
        }

        /* Sequence */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_LONG, 0x8201))) != MAPI_UNDEFINED) {
            ddword_ptr = (DDWORD*)filename->data;
            fprintf(fptr, "SEQUENCE:%i\n", (int) *ddword_ptr);
        }
        if ((filename=MAPIFindProperty(&(tnef->MapiProperties),
                        PROP_TAG(PT_BINARY, PR_SENDER_SEARCH_KEY)))
                != MAPI_UNDEFINED) {
            charptr = filename->data;
            charptr2 = strstr(charptr, ":");
            if (charptr2 == NULL)
                charptr2 = charptr;
            else
                charptr2++;
            fprintf(fptr, "ORGANIZER;CN=\"%s\":MAILTO:%s\n",
                    charptr2, charptr2);
        }

        /* Required Attendees */
        if ((filename = MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_STRING8, 0x823b))) != MAPI_UNDEFINED) {
	    /* We have a list of required participants, so
	       write them out. */
            if (filename->size > 1) {
                charptr = filename->data-1;
                charptr2=strstr(charptr+1, ";");
                while (charptr != NULL) {
                    charptr++;
                    charptr2 = strstr(charptr, ";");
                    if (charptr2 != NULL) {
                        *charptr2 = 0;
                    }
                    while (*charptr == ' ')
                        charptr++;
                    fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
                    fprintf(fptr, "ROLE=REQ-PARTICIPANT;RSVP=TRUE;");
                    fprintf(fptr, "CN=\"%s\":MAILTO:%s\n",
                                charptr, charptr);
                    charptr = charptr2;
                }
            }
            /* Optional attendees */
            if ((filename = MAPIFindUserProp(&(tnef->MapiProperties),
                            PROP_TAG(PT_STRING8, 0x823c))) != MAPI_UNDEFINED) {
                    /* The list of optional participants */
                if (filename->size > 1) {
                    charptr = filename->data-1;
                    charptr2=strstr(charptr+1, ";");
                    while (charptr != NULL) {
                        charptr++;
                        charptr2 = strstr(charptr, ";");
                        if (charptr2 != NULL) {
                            *charptr2 = 0;
                        }
                        while (*charptr == ' ')
                            charptr++;
                        fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
                        fprintf(fptr, "ROLE=OPT-PARTICIPANT;RSVP=TRUE;");
                        fprintf(fptr, "CN=\"%s\":MAILTO:%s\n",
                                charptr, charptr);
                        charptr = charptr2;
                    }
                }
            }
        } else if ((filename = MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_STRING8, 0x8238))) != MAPI_UNDEFINED) {
            if (filename->size > 1) {
                charptr = filename->data-1;
                charptr2=strstr(charptr+1, ";");
                while (charptr != NULL) {
                    charptr++;
                    charptr2 = strstr(charptr, ";");
                    if (charptr2 != NULL) {
                        *charptr2 = 0;
                    }
                    while (*charptr == ' ')
                        charptr++;
                    fprintf(fptr, "ATTENDEE;PARTSTAT=NEEDS-ACTION;");
                    fprintf(fptr, "ROLE=REQ-PARTICIPANT;RSVP=TRUE;");
                    fprintf(fptr, "CN=\"%s\":MAILTO:%s\n",
                                charptr, charptr);
                    charptr = charptr2;
                }
            }

        }
        /* Summary */
        filename = NULL;
        if((filename=MAPIFindProperty(&(tnef->MapiProperties),
                        PROP_TAG(PT_STRING8, PR_CONVERSATION_TOPIC)))
                != MAPI_UNDEFINED) {
            fprintf(fptr, "SUMMARY:");
            cstylefprint(fptr, filename);
            fprintf(fptr, "\n");
        }

        /* Description */
        if ((filename=MAPIFindProperty(&(tnef->MapiProperties),
                                PROP_TAG(PT_BINARY, PR_RTF_COMPRESSED)))
                != MAPI_UNDEFINED) {
            variableLength *buf;
	    buf = (variableLength *)g_malloc (sizeof(variableLength));
            if ((buf->data = DecompressRTF(filename, &(buf->size))) != NULL) {
                fprintf(fptr, "DESCRIPTION:");
                printRtf(fptr, buf);
                free(buf->data);
            }

        }

        /* Location */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_STRING8, 0x0002))) == MAPI_UNDEFINED) {
            if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                            PROP_TAG(PT_STRING8, 0x8208))) == MAPI_UNDEFINED) {
                filename = NULL;
            }
        }
        if (filename != NULL) {
            fprintf(fptr,"LOCATION: %s\n", filename->data);
        }
        /* Date Start */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_SYSTIME, 0x820d))) == MAPI_UNDEFINED) {
            if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                            PROP_TAG(PT_SYSTIME, 0x8516))) == MAPI_UNDEFINED) {
                filename=NULL;
            }
        }
        if (filename != NULL) {
            fprintf(fptr, "DTSTART:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n",
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }
        /* Date End */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_SYSTIME, 0x820e))) == MAPI_UNDEFINED) {
            if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                            PROP_TAG(PT_SYSTIME, 0x8517))) == MAPI_UNDEFINED) {
                filename=NULL;
            }
        }
        if (filename != NULL) {
            fprintf(fptr, "DTEND:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n",
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }
        /* Date Stamp */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_SYSTIME, 0x8202))) != MAPI_UNDEFINED) {
            fprintf(fptr, "CREATED:");
            MAPISysTimetoDTR(filename->data, &thedate);
            fprintf(fptr,"%04i%02i%02iT%02i%02i%02iZ\n",
                    thedate.wYear, thedate.wMonth, thedate.wDay,
                    thedate.wHour, thedate.wMinute, thedate.wSecond);
        }
        /* Class */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_BOOLEAN, 0x8506))) != MAPI_UNDEFINED) {
            ddword_ptr = (DDWORD*)filename->data;
            ddword_val = SwapDDWord((BYTE*)ddword_ptr);
            fprintf(fptr, "CLASS:" );
            if (*ddword_ptr == 1) {
                fprintf(fptr,"PRIVATE\n");
            } else {
                fprintf(fptr,"PUBLIC\n");
            }
        }
        /* Recurrence */
        filename = NULL;
        if ((filename=MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_BINARY, 0x8216))) != MAPI_UNDEFINED) {
            printRrule(fptr, filename->data, filename->size, tnef);
        }

        /* Wrap it up */
        fprintf(fptr, "END:VEVENT\n");
        fprintf(fptr, "END:VCALENDAR\n");
        fclose(fptr);
    }
}
コード例 #10
0
ファイル: tnef-plugin.c プロジェクト: ebbywiselyn/evolution
void saveVCard(TNEFStruct *tnef) {
    char ifilename[512];
    FILE *fptr;
    variableLength *vl;
    variableLength *pobox, *street, *city, *state, *zip, *country;
    dtr thedate;
    int boolean, i;

    if ((vl = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_DISPLAY_NAME))) == MAPI_UNDEFINED) {
        if ((vl=MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_COMPANY_NAME))) == MAPI_UNDEFINED) {
            if (tnef->subject.size > 0) {
                if (filepath == NULL) {
                    sprintf(ifilename, "%s.vcard", tnef->subject.data);
                } else {
                    sprintf(ifilename, "%s/%s.vcard", filepath, tnef->subject.data);
                }
            } else {
                if (filepath == NULL) {
                    sprintf(ifilename, "unknown.vcard");
                } else {
                    sprintf(ifilename, "%s/unknown.vcard", filepath);
                }
            }
        } else {
            if (filepath == NULL) {
                sprintf(ifilename, "%s.vcard", vl->data);
            } else {
                sprintf(ifilename, "%s/%s.vcard", filepath, vl->data);
            }
        }
    } else {
        if (filepath == NULL) {
            sprintf(ifilename, "%s.vcard", vl->data);
        } else {
            sprintf(ifilename, "%s/%s.vcard", filepath, vl->data);
        }
    }
    for(i=0; i<strlen(ifilename); i++)
        if (ifilename[i] == ' ')
            ifilename[i] = '_';
    printf("%s\n", ifilename);

    if ((fptr = fopen(ifilename, "wb"))==NULL) {
            printf("Error writing file to disk!");
    } else {
        fprintf(fptr, "BEGIN:VCARD\n");
        fprintf(fptr, "VERSION:2.1\n");
        if (vl != MAPI_UNDEFINED) {
            fprintf(fptr, "FN:%s\n", vl->data);
        }
        fprintProperty(tnef, fptr, PT_STRING8, PR_NICKNAME, "NICKNAME:%s\n");
        fprintUserProp(tnef, fptr, PT_STRING8, 0x8554, "MAILER:Microsoft Outlook %s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_SPOUSE_NAME, "X-EVOLUTION-SPOUSE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_MANAGER_NAME, "X-EVOLUTION-MANAGER:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_ASSISTANT, "X-EVOLUTION-ASSISTANT:%s\n");

        /* Organizational */
        if ((vl=MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_COMPANY_NAME))) != MAPI_UNDEFINED) {
            if (vl->size > 0) {
                if ((vl->size == 1) && (vl->data[0] == 0)) {
                } else {
                    fprintf(fptr,"ORG:%s", vl->data);
                    if ((vl=MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_DEPARTMENT_NAME))) != MAPI_UNDEFINED) {
                        fprintf(fptr,";%s", vl->data);
                    }
                    fprintf(fptr, "\n");
                }
            }
        }

        fprintProperty(tnef, fptr, PT_STRING8, PR_OFFICE_LOCATION, "X-EVOLUTION-OFFICE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_TITLE, "TITLE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_PROFESSION, "ROLE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_BODY, "NOTE:%s\n");
        if (tnef->body.size > 0) {
            fprintf(fptr, "NOTE;QUOTED-PRINTABLE:");
            quotedfprint(fptr, &(tnef->body));
            fprintf(fptr,"\n");
        }


        /* Business Address */
        boolean = 0;
        if ((pobox = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_POST_OFFICE_BOX))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((street = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_STREET_ADDRESS))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((city = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_LOCALITY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((state = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_STATE_OR_PROVINCE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((zip = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_POSTAL_CODE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((country = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_COUNTRY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if (boolean == 1) {
            fprintf(fptr, "ADR;QUOTED-PRINTABLE;WORK:");
            if (pobox != MAPI_UNDEFINED) {
                quotedfprint(fptr, pobox);
            }
            fprintf(fptr, ";;");
            if (street != MAPI_UNDEFINED) {
                quotedfprint(fptr, street);
            }
            fprintf(fptr, ";");
            if (city != MAPI_UNDEFINED) {
                quotedfprint(fptr, city);
            }
            fprintf(fptr, ";");
            if (state != MAPI_UNDEFINED) {
                quotedfprint(fptr, state);
            }
            fprintf(fptr, ";");
            if (zip != MAPI_UNDEFINED) {
                quotedfprint(fptr, zip);
            }
            fprintf(fptr, ";");
            if (country != MAPI_UNDEFINED) {
                quotedfprint(fptr, country);
            }
            fprintf(fptr,"\n");
            if ((vl = MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x801b))) != MAPI_UNDEFINED) {
                fprintf(fptr, "LABEL;QUOTED-PRINTABLE;WORK:");
                quotedfprint(fptr, vl);
                fprintf(fptr,"\n");
            }
        }

        /* Home Address */
        boolean = 0;
        if ((pobox = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_POST_OFFICE_BOX))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((street = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_STREET))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((city = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_CITY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((state = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_STATE_OR_PROVINCE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((zip = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_POSTAL_CODE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((country = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_HOME_ADDRESS_COUNTRY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if (boolean == 1) {
            fprintf(fptr, "ADR;QUOTED-PRINTABLE;HOME:");
            if (pobox != MAPI_UNDEFINED) {
                quotedfprint(fptr, pobox);
            }
            fprintf(fptr, ";;");
            if (street != MAPI_UNDEFINED) {
                quotedfprint(fptr, street);
            }
            fprintf(fptr, ";");
            if (city != MAPI_UNDEFINED) {
                quotedfprint(fptr, city);
            }
            fprintf(fptr, ";");
            if (state != MAPI_UNDEFINED) {
                quotedfprint(fptr, state);
            }
            fprintf(fptr, ";");
            if (zip != MAPI_UNDEFINED) {
                quotedfprint(fptr, zip);
            }
            fprintf(fptr, ";");
            if (country != MAPI_UNDEFINED) {
                quotedfprint(fptr, country);
            }
            fprintf(fptr,"\n");
            if ((vl = MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x801a))) != MAPI_UNDEFINED) {
                fprintf(fptr, "LABEL;QUOTED-PRINTABLE;WORK:");
                quotedfprint(fptr, vl);
                fprintf(fptr,"\n");
            }
        }

        /* Other Address */
        boolean = 0;
        if ((pobox = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_POST_OFFICE_BOX))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((street = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_STREET))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((city = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_CITY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((state = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_STATE_OR_PROVINCE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((zip = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_POSTAL_CODE))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if ((country = MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, PR_OTHER_ADDRESS_COUNTRY))) != MAPI_UNDEFINED) {
            boolean = 1;
        }
        if (boolean == 1) {
            fprintf(fptr, "ADR;QUOTED-PRINTABLE;OTHER:");
            if (pobox != MAPI_UNDEFINED) {
                quotedfprint(fptr, pobox);
            }
            fprintf(fptr, ";;");
            if (street != MAPI_UNDEFINED) {
                quotedfprint(fptr, street);
            }
            fprintf(fptr, ";");
            if (city != MAPI_UNDEFINED) {
                quotedfprint(fptr, city);
            }
            fprintf(fptr, ";");
            if (state != MAPI_UNDEFINED) {
                quotedfprint(fptr, state);
            }
            fprintf(fptr, ";");
            if (zip != MAPI_UNDEFINED) {
                quotedfprint(fptr, zip);
            }
            fprintf(fptr, ";");
            if (country != MAPI_UNDEFINED) {
                quotedfprint(fptr, country);
            }
            fprintf(fptr,"\n");
        }


        fprintProperty(tnef, fptr, PT_STRING8, PR_CALLBACK_TELEPHONE_NUMBER, "TEL;X-EVOLUTION-CALLBACK:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_PRIMARY_TELEPHONE_NUMBER, "TEL;PREF:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_MOBILE_TELEPHONE_NUMBER, "TEL;CELL:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_RADIO_TELEPHONE_NUMBER, "TEL;X-EVOLUTION-RADIO:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_CAR_TELEPHONE_NUMBER, "TEL;CAR:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_OTHER_TELEPHONE_NUMBER, "TEL;VOICE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_PAGER_TELEPHONE_NUMBER, "TEL;PAGER:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_TELEX_NUMBER, "TEL;X-EVOLUTION-TELEX:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_ISDN_NUMBER, "TEL;ISDN:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_HOME2_TELEPHONE_NUMBER, "TEL;HOME:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_TTYTDD_PHONE_NUMBER, "TEL;X-EVOLUTION-TTYTDD:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_HOME_TELEPHONE_NUMBER, "TEL;HOME;VOICE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_ASSISTANT_TELEPHONE_NUMBER, "TEL;X-EVOLUTION-ASSISTANT:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_COMPANY_MAIN_PHONE_NUMBER, "TEL;WORK:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_BUSINESS_TELEPHONE_NUMBER, "TEL;WORK:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_BUSINESS2_TELEPHONE_NUMBER, "TEL;WORK;VOICE:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_PRIMARY_FAX_NUMBER, "TEL;PREF;FAX:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_BUSINESS_FAX_NUMBER, "TEL;WORK;FAX:%s\n");
        fprintProperty(tnef, fptr, PT_STRING8, PR_HOME_FAX_NUMBER, "TEL;HOME;FAX:%s\n");


        /* Email addresses */
        if ((vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x8083))) == MAPI_UNDEFINED) {
            vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x8084));
        }
        if (vl != MAPI_UNDEFINED) {
            if (vl->size > 0)
                fprintf(fptr, "EMAIL:%s\n", vl->data);
        }
        if ((vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x8093))) == MAPI_UNDEFINED) {
            vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x8094));
        }
        if (vl != MAPI_UNDEFINED) {
            if (vl->size > 0)
                fprintf(fptr, "EMAIL:%s\n", vl->data);
        }
        if ((vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x80a3))) == MAPI_UNDEFINED) {
            vl=MAPIFindUserProp(&(tnef->MapiProperties), PROP_TAG(PT_STRING8, 0x80a4));
        }
        if (vl != MAPI_UNDEFINED) {
            if (vl->size > 0)
                fprintf(fptr, "EMAIL:%s\n", vl->data);
        }

        fprintProperty(tnef, fptr, PT_STRING8, PR_BUSINESS_HOME_PAGE, "URL:%s\n");
        fprintUserProp(tnef, fptr, PT_STRING8, 0x80d8, "FBURL:%s\n");



        /* Birthday */
        if ((vl=MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_SYSTIME, PR_BIRTHDAY))) != MAPI_UNDEFINED) {
            fprintf(fptr, "BDAY:");
            MAPISysTimetoDTR(vl->data, &thedate);
            fprintf(fptr, "%i-%02i-%02i\n", thedate.wYear, thedate.wMonth, thedate.wDay);
        }

        /* Anniversary */
        if ((vl=MAPIFindProperty(&(tnef->MapiProperties), PROP_TAG(PT_SYSTIME, PR_WEDDING_ANNIVERSARY))) != MAPI_UNDEFINED) {
            fprintf(fptr, "X-EVOLUTION-ANNIVERSARY:");
            MAPISysTimetoDTR(vl->data, &thedate);
            fprintf(fptr, "%i-%02i-%02i\n", thedate.wYear, thedate.wMonth, thedate.wDay);
        }
        fprintf(fptr, "END:VCARD\n");
    }
}
コード例 #11
0
ファイル: tnef-plugin.c プロジェクト: ebbywiselyn/evolution
void processTnef(TNEFStruct *tnef) {
    variableLength *filename;
    variableLength *filedata;
    Attachment *p;
    int RealAttachment;
    int object;
    char * ifilename;
    int i, count;
    int foundCal=0;

    FILE *fptr;
    ifilename = (char *) g_malloc(sizeof(char) * 256);

    /* First see if this requires special processing. */
    /* ie: it's a Contact Card, Task, or Meeting request (vCal/vCard) */
    if (tnef->messageClass[0] != 0)  {
        if (strcmp(tnef->messageClass, "IPM.Contact") == 0) {
            saveVCard(tnef);
        }
        if (strcmp(tnef->messageClass, "IPM.Task") == 0) {
            saveVTask(tnef);
        }
        if (strcmp(tnef->messageClass, "IPM.Appointment") == 0) {
            saveVCalendar(tnef);
            foundCal = 1;
        }
    }

    if ((filename = MAPIFindUserProp(&(tnef->MapiProperties),
                        PROP_TAG(PT_STRING8,0x24))) != MAPI_UNDEFINED) {
        if (strcmp(filename->data, "IPM.Appointment") == 0) {
             /* If it's "indicated" twice, we don't want to save 2 calendar entries. */
            if (foundCal == 0) {
                saveVCalendar(tnef);
            }
        }
    }

    if (strcmp(tnef->messageClass, "IPM.Microsoft Mail.Note") == 0) {
        if ((saveRTF == 1) && (tnef->subject.size > 0)) {
            /*  Description */
            if ((filename=MAPIFindProperty(&(tnef->MapiProperties),
					   PROP_TAG(PT_BINARY, PR_RTF_COMPRESSED)))
                    != MAPI_UNDEFINED) {
                variableLength *buf;
		buf = (variableLength *)g_malloc (sizeof(variableLength));
		buf->data="";
		buf->size=0;
                if ((buf->data = DecompressRTF(filename, &(buf->size))) != NULL) {
                    if (filepath == NULL) {
                        sprintf(ifilename, "%s.rtf", tnef->subject.data);
                    } else {
                        sprintf(ifilename, "%s/%s.rtf", filepath, tnef->subject.data);
                    }
                    for(i=0; i<strlen(ifilename); i++)
                        if (ifilename[i] == ' ')
                            ifilename[i] = '_';

                    if ((fptr = fopen(ifilename, "wb"))==NULL) {
                        printf("ERROR: Error writing file to disk!");
                    } else {
                        fwrite(buf->data,
                                sizeof(BYTE),
                                buf->size,
                                fptr);
                        fclose(fptr);
                    }
                    free(buf->data);
		    buf->data="";
		    buf->size=0;
                }
            }
	}
    }

    /* Now process each attachment */
    p = tnef->starting_attach.next;
    count = 0;
    while (p != NULL) {
        count++;
        /* Make sure it has a size. */
        if (p->FileData.size > 0) {
            object = 1;

            /* See if the contents are stored as "attached data" */
	    /* Inside the MAPI blocks. */
            if((filedata = MAPIFindProperty(&(p->MAPI),
                                    PROP_TAG(PT_OBJECT, PR_ATTACH_DATA_OBJ)))
                    == MAPI_UNDEFINED) {
                if((filedata = MAPIFindProperty(&(p->MAPI),
                                    PROP_TAG(PT_BINARY, PR_ATTACH_DATA_OBJ)))
		   == MAPI_UNDEFINED) {
                    /* Nope, standard TNEF stuff. */
                    filedata = &(p->FileData);
                    object = 0;
                }
            }
            /* See if this is an embedded TNEF stream. */
            RealAttachment = 1;
            if (object == 1) {
                /*  This is an "embedded object", so skip the */
                /* 16-byte identifier first. */
                TNEFStruct *emb_tnef;
		emb_tnef = (TNEFStruct *) g_malloc(sizeof(TNEFStruct));
                DWORD signature;
                memcpy(&signature, filedata->data+16, sizeof(DWORD));
                if (TNEFCheckForSignature(signature) == 0) {
                    /* Has a TNEF signature, so process it. */
                    TNEFInitialize(emb_tnef);
                    emb_tnef->Debug = tnef->Debug;
                    if (TNEFParseMemory(filedata->data+16,
                             filedata->size-16, emb_tnef) != -1) {
                        processTnef(emb_tnef);
                        RealAttachment = 0;
                    }
                    TNEFFree(emb_tnef);
                }
            } else {
                TNEFStruct *emb_tnef;
		emb_tnef = (TNEFStruct *) g_malloc(sizeof(TNEFStruct));
                DWORD signature;
                memcpy(&signature, filedata->data, sizeof(DWORD));
                if (TNEFCheckForSignature(signature) == 0) {
                    /* Has a TNEF signature, so process it. */
                    TNEFInitialize(emb_tnef);
                    emb_tnef->Debug = tnef->Debug;
                    if (TNEFParseMemory(filedata->data,
                            filedata->size, emb_tnef) != -1) {
                        processTnef(emb_tnef);
                        RealAttachment = 0;
                    }
                    TNEFFree(emb_tnef);
                }
            }
            if ((RealAttachment == 1) || (saveintermediate == 1)) {
                /* Ok, it's not an embedded stream, so now we */
		/* process it. */
                if ((filename = MAPIFindProperty(&(p->MAPI),
                                        PROP_TAG(30,0x3707)))
                        == MAPI_UNDEFINED) {
                    if ((filename = MAPIFindProperty(&(p->MAPI),
                                        PROP_TAG(30,0x3001)))
                            == MAPI_UNDEFINED) {
                        filename = &(p->Title);
                    }
                }
                if (filename->size == 1) {
                    filename = (variableLength*)malloc(sizeof(variableLength));
                    filename->size = 20;
                    filename->data = (char*)malloc(20);
                    sprintf(filename->data, "file_%03i.dat", count);
                }
                if (filepath == NULL) {
                    sprintf(ifilename, "%s", filename->data);
                } else {
                    sprintf(ifilename, "%s/%s", filepath, filename->data);
                }
                for(i=0; i<strlen(ifilename); i++)
                    if (ifilename[i] == ' ')
                        ifilename[i] = '_';

		if ((fptr = fopen(ifilename, "wb"))==NULL) {
		    printf("ERROR: Error writing file to disk!");
		} else {
		    if (object == 1) {
			fwrite(filedata->data + 16,
			       sizeof(BYTE),
			       filedata->size - 16,
			       fptr);
		    } else {
			fwrite(filedata->data,
			       sizeof(BYTE),
			       filedata->size,
			       fptr);
		    }
		    fclose(fptr);
		}
            }
        } /* if size>0 */
        p=p->next;
    } /* while p!= null */

    g_free (ifilename);
}