Five Stars

tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hi,

 

I'm trying to rename file attachments from email files, pulled with tFileInputMail (from tPop), based on the subject line.

 

I found this: https://www.talendforge.org/forum/viewtopic.php?id=21666

However I can't see the images that contain the solution and I am a bit lost on how to pass the values to tFileCopy (tJavaRow before to change name).

 

I'm thinking something like:

tPop ---- iterate ---> tFileInputMail --- (row) ---> tJavaRow -----> tFlowtoIterate ----> tFileCopy

 

But I can't extract/pass the attachment name from tFileInputMail.

 

Thanks.

 

Regards,

V

1 ACCEPTED SOLUTION

Accepted Solutions
Five Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hi med,

 

Many thanks for your help. I've finally got back to this and have cracked it with your help/guidance. 

 

I now have it working with (after pulling all emails into a folder):

tFileList -(iterate)-> tFileInputMail -(row)> tJavaRow -> onComponentOK -> tFileList -(iterate)-> tFileCopy

 

*onComponentOk can be replaced with -(row)> tFlowtoIterate -(iterate)-> 

 

tJavaCode: globalMap.put("subject",row1.subject)

tFileCopy:

  • Rename - Destination filename = (String)globalMap.get("subject")+".csv"
  • Remove Source File

 

Note: we have to use tJavaRow because "Where is tJava used in the Job design: The Java code inserted through the tJava is executed first but only once in the subjob" - so we couldn't read the initial row value.

 

Regards,

Vitor Lopes

8 REPLIES
Six Stars med
Six Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hello,

 

When you retrieve the attachment files using the tFileInputMail you specify the folder Path and not the File attachment name.

 

So in your case, you can develop 2 subjobs :

1- Retrieve the attachments files and put them in the folder.

2- Use tFilelist to fetch the folder and in each iteration you can uste tCopy to rename the files.

 

BR,

Five Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hi,

Thanks for your reply. I had gotten close to that, but I still don't know how to pass/use the subject to generate the new filename.

Should I just use a tjavarow?

tFileInputMail -> tjavarow -> tfilelist -> tfilecopy

Just sounds super complicated for a simple operation. But maybe it is the best way.

Cheers,
V
Six Stars med
Six Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hello,

 

In fact

 

tFileInputMail allow you to retrieve the File in specific folder (you specify the folder).

 

you can use directly :

 

tFileInputMail (On component OK) -> tfilelist (specify the folder which contain the files) -> tfilecopy

 

No need to use tJavaRow.

 

BR,

Med

Five Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Yes, but I need to read the subject from each email individually to rename each file. That is the real issue Smiley Wink

V
Six Stars med
Six Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hello,

 

Ok i get what you need.

 

So the idea is to retrieve in each iteration the subject and then use this subject to rename your files.

 

so you can use tFileinputMail (iterate)==>tJava(iterate)==>tFilelist==>tCopy

 

beause you cant use tJavaRow in iterate.

 

GoodLuck

Five Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

OK, so nearly there. 

 

Question, how do I access the subject in tJava?

 

 

Many thanks for your time, and help so far

 

Cheers,

V

Six Stars med
Six Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hello,

 

I try to access to the subject using tJava but no way (the variables are not available for this component).

 

Try to use tFlowIterate ( tFileInputMail (main_row)==>tFlowIterate(titerate)==>tCopyFile

 

Let me know if it works.

Five Stars

Re: tFileInputMail - rename multiple attachments (subject to flow/iterate)

Hi med,

 

Many thanks for your help. I've finally got back to this and have cracked it with your help/guidance. 

 

I now have it working with (after pulling all emails into a folder):

tFileList -(iterate)-> tFileInputMail -(row)> tJavaRow -> onComponentOK -> tFileList -(iterate)-> tFileCopy

 

*onComponentOk can be replaced with -(row)> tFlowtoIterate -(iterate)-> 

 

tJavaCode: globalMap.put("subject",row1.subject)

tFileCopy:

  • Rename - Destination filename = (String)globalMap.get("subject")+".csv"
  • Remove Source File

 

Note: we have to use tJavaRow because "Where is tJava used in the Job design: The Java code inserted through the tJava is executed first but only once in the subjob" - so we couldn't read the initial row value.

 

Regards,

Vitor Lopes