Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving Thread as PDF, in Addition to Attachments in the Same Folder #36

Closed
Hanshaw opened this issue Apr 1, 2020 · 4 comments
Closed

Comments

@Hanshaw
Copy link

Hanshaw commented Apr 1, 2020

Hello,

I believe there is an issue when attempting to convert the thread to a pdf and save it into the same folder as the attachments when they are stripped.

Here is my rule:

 {
    // Saves Attachments.
    "filter": "has:attachment",
    "saveThreadPDF": true,
    "folder": "'Testing/REQ-'yyyy-MM-dd-HH:mm:ss",
    "filenameTo": "'REQ-'yyyy-MM-dd'-T-'HH:mm:ss'-%s'",
    "archive": true
  }   

When this is executed it actually creates two folders, one for the attachments and one for the email that is converted to pdf.

The attachments go to a new folder such as: Testing/REQ-2020-04-01-08:28:32
On the other hand, the converted pdf goes to a new(different) folder: 'Testing/REQ-'yyyy-MM-dd-HH:mm:ss . In addition, there is two copies of the email in the folder with the subject as the filename.

The goal would be to store everything in the same folder that is created.

@mrrosenthal85
Copy link

yes, this is important, how to achieve this?

@maxsnet
Copy link

maxsnet commented May 13, 2020

I had this issue too so I fixed it in my patch that adds a log file, but you can do it directly like this:

In function processThreadToPdf, update rule.folder accordingly to remove all '

replace(/\'/g,'')

Check https://regexr.com/ to test RegEx, it is pretty cool :)


/**
* Generate a PDF document for the whole thread using HTML from .
 */
function processThreadToPdf(thread, rule) {
  Logger.log("INFO: Saving PDF copy of thread '" + thread.getFirstMessageSubject() + "'");
  rule.folder = rule.folder.replace(/\'/g,'');
  var folder = getOrCreateFolder(rule.folder);
  var html = processThreadToHtml(thread);
  var blob = Utilities.newBlob(html, 'text/html');
  var pdf = folder.createFile(blob.getAs('application/pdf')).setName(thread.getFirstMessageSubject() + ".pdf");
  f_addaline_log_file_SpreadsheetApp(thread.getFirstMessageSubject(),thread.getLastMessageDate(),thread.getId(),"https://mail.google.com/mail/u/0/#inbox/" + thread.getId(),"Thread",pdf.getName(),pdf.getUrl());
  return pdf;
}

@maxsnet
Copy link

maxsnet commented May 13, 2020

Thinking about it, I didn't test if that bugs the regex replace with the date... can you tell me ?

maxsnet added a commit to maxsnet/gmail2gdrive that referenced this issue May 14, 2020
When saving thread + attachments, remove the ' to the folder for Thread save.
Issue ahochsteger#36
ahochsteger added a commit that referenced this issue Jun 18, 2022
resolves Saving Thread as PDF, in Addition to Attachments in the Same Folder #36
@ahochsteger
Copy link
Owner

@maxsnet thanks for the contribution, is now committed to the master branch.

github-actions bot pushed a commit that referenced this issue Aug 22, 2023
# [2.0.0](1.1.0...2.0.0) (2023-08-22)

### Bug Fixes

* add mailmap to fix wrong historic name/email ([cb43d48](cb43d48))
* add missing dryRun handling ([60f1e19](60f1e19))
* add missing processor base class ([3870c14](3870c14))
* ci workflow + release config ([49ae903](49ae903))
* cleanup files after clasp run ([d70cb44](d70cb44))
* code smells ([b76bcd9](b76bcd9))
* commit missing changes from last refactoring ([f7f8f3c](f7f8f3c))
* corrupted attachments (string -> blob) ([d698185](d698185))
* decorator implementation ([7afc98f](7afc98f))
* docs build ([8eda0e0](8eda0e0))
* eliminate defaults from converted config ([1fd9d7f](1fd9d7f))
* ensure uniqueness of example function names ([38ddbcd](38ddbcd))
* env context structure ([b94b53a](b94b53a))
* failing multiple substitutions of same placeholder ([d5ca9ef](d5ca9ef))
* folder conversion without single quotes ([96a6b47](96a6b47))
* github pages deployment ([a9f08c8](a9f08c8))
* github pages deployment ([315c0ff](315c0ff))
* GmailProcessor.runWithConfigJson() ([93446d6](93446d6))
* init e2e tests ([28d974b](28d974b))
* init e2e tests ([9e00810](9e00810))
* logging for generated examples ([9229a3f](9229a3f))
* old reference to processedLabel ([3f7b2ee](3f7b2ee))
* pages deployment + coverage ([506dbb2](506dbb2))
* regression error + example scopes ([73e87de](73e87de))
* release command in workflow ([203a66c](203a66c))
* releases ci steps ([095e5a3](095e5a3))
* remaining references to .clasp.json ([b4f5561](b4f5561))
* remove old action refs + styling ([30b450b](30b450b))
* remove performance.now() ([f18f93f](f18f93f))
* remove test exit in clasp.sh ([a50f4aa](a50f4aa))
* remove unused rootTitle ([72385cb](72385cb))
* remove workflow permission declaration ([7e726ee](7e726ee))
* revert name of attachment.contentType(Regex) ([95b5297](95b5297))
* static action method handling ([999091e](999091e))
* store email PDF in same folder as attachments ([74a439d](74a439d)), closes [#36](#36)
* syntax error ([08af1ef](08af1ef))
* test errors due to buildMatchConfig changes ([df97b68](df97b68))
* timezone in some ([e9bc0d0](e9bc0d0))
* trailing hash in schema reference ([a2749f8](a2749f8))
* typo `messgage.matched` -> `message.matched` ([e97d909](e97d909))
* use logger passed ([4d00ccf](4d00ccf))
* wrong branch in .releaserc ([de7b9ef](de7b9ef))
* wrong start index of gmail app search ([a1b3f34](a1b3f34))

### Code Refactoring

* rename gmail2gdrive -> gmail-processor ([525e3db](525e3db))

### Features

* add action handling to processors ([a121889](a121889))
* add compatibility for %filename pattern ([e3bb858](e3bb858)), closes [#50](#50)
* add conflict strategies backup/update, tests ([d370a8e](d370a8e))
* add date filter at rule level ([#60](#60)) ([ecdb2ea](ecdb2ea))
* add decorator-driven action registry ([584ed75](584ed75))
* add dryrun mode ([c70c44b](c70c44b))
* add github pages publishing ([5d4ff4d](5d4ff4d))
* add global actions ([96c0707](96c0707))
* add handler name config ([30920ab](30920ab))
* add message date matching ([34dba8c](34dba8c))
* add meta infos + docs generation ([f080d44](f080d44))
* add option for using a rule counter with filenameTo ([#58](#58)) ([333212e](333212e))
* add possibility to store each individual email as PDF ([#73](#73)) ([88f3c34](88f3c34))
* add processing context substitution ([39c0e5b](39c0e5b))
* add processing stages to actions (pre/post) ([650654d](650654d))
* add regex matching to thread config ([8bf43df](8bf43df))
* add schema validation, refactor generation ([7937fb3](7937fb3))
* add sender domain to substitution map ([3e657ec](3e657ec))
* add SpreadsheetAdapter for logSheet handling ([bf518c1](bf518c1)), closes [#37](#37)
* add substitution to match config strings ([b5ea2be](b5ea2be))
* add support for Shared Drives ([#72](#72)) ([e2adc68](e2adc68))
* add thread matching ([740fab3](740fab3))
* allow subject with '%s' in folder name ([#48](#48)) ([957621b](957621b))
* Initial draft of re-implementation for v2 ([91c293b](91c293b))
* more global configs + main processing stage ([791d1cb](791d1cb))
* store single message as PDF to GMail ([c9abd9c](c9abd9c))
* streamline run methods ([9dd733c](9dd733c))
* substitute user info + variables ([1d67c13](1d67c13))

### BREAKING CHANGES

* marker to trigger major version increment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants